Get yAxis end value

How can I get (read) the yAxis end value from a chart object?

Background: I am super-imposing 2 charts; and it would make it much easier if I could get the yAxis end value from the first chart, and then aply to the 2nd, instead of doing the calculation up front.

Hello,

try the following:

var end = chart1.config.yAxis.end;

That helps, next issue:

It appears that I need to provide start:, end: and step: for the overlay chart.

Using:
alert(mychart.config.yAxis.start);
alert(mychart.config.yAxis.end);
alert(mychart.config.yAxis.step);

I am getting good values for .start and .end, but .step is undefined.

I am creating the 2nd overlay chart on the “onXLE” event of the 1st chart.

How can I pull in the value of the .step of the 1st chart, or how can I ignore having to provide a step for the 2nd overlay chart?

Thanks!

Chart uses the following approach to calculate scale:

var values = chart1._getLimits();
var axis = chart1._calculateScale(values.min, values.max);

axis is an object that contains start, step and end properties.

Methods _getLimits and _calculateScale are private.

Almost there…

The axis.end doesn’t give the end value of the yAxis, but rather the end - step

So, if the chart is

start: 0
end: 6000
step: 1000

then:
axis.start == 0
axis.end == 5000
axis.step == 1000

But it’s not as simple as adding one step to the end to calculate the “true” end though. In the above example that would work, but in the following example it wouldn’t:

start: 0
end: 5000
step: 1000

then:
axis.start == 0
axis.end == 4000
axis.step == 500

What I ended up using is a mix of the above methods to build chart2:

        yAxis: {
            title: "Hours",
            start: chart1.config.yAxis.start,
            end: chart1.config.yAxis.end,
            step: chart1._calculateScale(chart1.config.yAxis.start,chart1.config.yAxis.end).step
        },

And that, allthough not the pretiest, works well for me :slight_smile: