Home Forums Chart Support AxisY and AxisY2 margin/width

AxisY and AxisY2 margin/width

Viewing 4 posts - 1 through 4 (of 4 total)
  • #34391

    Hi there, im having a little problem with that.
    I want to have 2 charts with different values (that mean different maximums) with same width or margin.
    jsfiddle
    I let you an image to clarify what I mean Example

    By the way, you need to fix this forum, this is like the 5th time that i tried to post the same question because cant send it…

    #34450

    @nerviozzo96,

    Aligning y-axis for multiple charts can be achieved by setting the margin property. The margin value has to be calculated based on the bounds of y-axis as shown in the code below –

    var axisYBoundMax = 0;
    for (var i=0; i<charts.length; i++) {
      axisYBoundMax = Math.max(axisYBoundMax, charts[i].axisY[0].bounds.x2);
    }
    
    for(var i = 0; i < charts.length; i++) {
      charts[i].axisY[0].set("margin", axisYBoundMax - (charts[i].axisY[0].bounds.x2 - charts[i].axisY[0].bounds.x1));
    } 

    Also, kindly take a look at this updated JSFiddle with the code to align the y-axis for multiple charts.

    align y-axis across multiple charts

    Sorry for the inconvenience caused while posting on the forum.


    Adithya Menon
    Team CanvasJS

    #34509

    Great! Thanks, I guess the same applies for the x axis right?

    #34523

    @nerviozzo96,

    Yes, you can align the x-axis across multiple charts using the same logic as mentioned above.


    Adithya Menon
    Team CanvasJS

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.