Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
132 views
in Technique[技术] by (71.8m points)

javascript - How to set a static minimum value for axes in Highcharts

I have time-based data that ranges from 1 to 500. Time is plotted on the x axis and the values are on the y axis.

When the range between the minimum and maximum data-points is great the y-axis' start label is 0. I can tell Highcharts not to display the label by setting yAxis.startOnTick = false; but that's is not really what I'm after.

Here is a jsfiddle of the problem where you cannot tell if the first point is 0 or some other value. Having 0 here also looks like the min range for y is 0, not 1.

Can Highcharts display the first label and the first label should always be set to the minimum value in the dataset (relative to its axis).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I am amazed how difficult this is. Not an optimal solution, but the best I can dream up with HighChart's api:

var someData = [1,5,82,9,300,5,42,199,5,6,99,1,56,52,250,64];

var chart = new Highcharts.Chart({

    chart: {
        renderTo: 'container'
    },
    yAxis:{
        min: -10,
        tickInterval: 1,
        labels: {
            formatter: function() {
                if (this.value < someData[0])
                    return null;
                else if (this.value == someData[0])
                    return this.value;
                else if (this.value % 50 == 0)
                    return this.value;
            }
        }
    },
    series: [{
        data: someData
    }]

});

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...