简体   繁体   中英

How to set yAxis min/max in Highcharts synchronized chart with JSON

I am working with the synchronised chart of Highchart. Pretty cool. However, I would like to »dictate« the min and max values for the yAxis. I added these two parameters into the JSON file, but they are not being accepted unfortunately.

JSON file:

    "unit": "km/h",
    "type": "line",
    "min": -2,
    "max": 16,

yAxis definition:

     yAxis: {
        title: {
           text: null
        },
        min: dataset.min,
        max: dataset.max
     },

but that doesn't work. Any idea why? Here is the original graphic I am working with. Here is a fiddle .

In Highcharts API we can read:

max: number, null

...

If the endOnTick option is true, the max value might be rounded up. (...)

As a solution disable startOnTick and endOnTick options or use tickPositioner function to calculate and set tick postion manually, for example:

            yAxis: {
                ...,
                tickPositioner: function(){
                    var ticks = [],
                    step = (dataset.max - dataset.min) / 4;

                  for (var i = dataset.min; i <= dataset.max; i += step) {
                    ticks.push(i);
                  }

                  return ticks;
                }
            }

Live demo: https://jsfiddle.net/BlackLabel/ev5hz0pk/

API Reference:

https://api.highcharts.com/highcharts/yAxis.max

https://api.highcharts.com/highcharts/yAxis.tickPositioner

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM