Highcharts中的最小值不起作用

时间:2014-09-08 21:58:43

标签: javascript jquery highcharts

所以我使用此代码创建一个高图线图

http://jsfiddle.net/3oLh5r2w/

$(function () {
    $('#container').highcharts({
        chart: {
            zoomType: 'x'
        },
        title: {
            text: 'USD to EUR exchange rate from 2006 through 2008'
        },
        subtitle: {
            text: document.ontouchstart === undefined ?
                    'Click and drag in the plot area to zoom in' :
                    'Pinch the chart to zoom in'
        },
        xAxis: {
            type: 'datetime',
            minRange: 14 * 24 * 3600000 // fourteen days
        },
        yAxis: {
            title: {
                text: 'Exchange rate'
            },
            floor:1,
            min: 1,
            max: 300,
            reversed: true,
        },
        legend: {
            enabled: false
        },
        plotOptions: {
            area: {
                fillColor: {
                    linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
                    stops: [
                        [0, Highcharts.getOptions().colors[0]],
                        [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
                    ]
                },
                marker: {
                    radius: 2
                },
                lineWidth: 1,
                states: {
                    hover: {
                        lineWidth: 1
                    }
                },
                threshold: null
            }
        },

        series: [{
            type: 'line',
            name: 'USD to EUR',
            pointInterval: 24 * 3600 * 1000,
            pointStart: Date.UTC(2006, 0, 1),
            data: [
                83, 28, 253, 113, 72, 177, 279, 71, 228, 72, 54, 162, 275, 246, 111, 119, 225, 19, 244, 102, 1, 75
            ]
        }]
    });
});

在小提琴中,我试图使它成为yaxis总是显示1 - 300.我遇到的问题是它总是向下舍入到0.我尝试使用startOnTick,但它没有做任何事情。我能找到的唯一让它正常工作的是setExtremes,但它只能通过像点击功能这样的后加载功能激活。

我怎样才能让它正常工作?

2 个答案:

答案 0 :(得分:1)

设置startOnTick : false

这里是更新的小提琴

http://jsfiddle.net/3oLh5r2w/2/

这是文档

轴的最小值。如果为null,则自动计算最小值。 如果startOnTick选项为true,则最小值可能会向下舍入。

答案 1 :(得分:1)

如果你将min设置为1,你需要有tickInterval,它允许达到300.其他解决方案正在使用tickPositions / tickPositioner

编辑: 示例:http://jsfiddle.net/3oLh5r2w/4/ tickPositions