如何在Highcharts中设置轴的静态最小值 [英] How to set a static minimum value for axes in Highcharts

查看:428
本文介绍了如何在Highcharts中设置轴的静态最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有基于时间的数据,范围从1到500.时间绘制在X轴上,数值在Y轴上。

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.

当范围我可以告诉Highcharts不要通过设置 yAxis.startOnTick = false;来显示标签; 在最小和最大数据点之间是很好的,但那不是我真正想要的。

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.

这里有一个问题的jsfiddle ,你不能分辨第一个点是否为0或其他值。这里的0也看起来像y的最小范围是
0,而不是1。

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可以显示第一个标签,并且应始终设置第一个标签到数据集中的最小值(相对于它的轴)。

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).

推荐答案

我很惊讶这是多么困难。不是最佳的解决方案,但最好的我可以用HighChart的api来做梦

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
    }]

});

这篇关于如何在Highcharts中设置轴的静态最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆