Change range in Highstock dynamically

我是研究僧i 提交于 2019-12-02 02:43:13

问题


I want to change the range in a chart dynamically. If I go from a big value to a smaller, everything works fine. But if I want to go to the bigger again, nothing happens.

You can try this here: http://jsfiddle.net/Charissima/wkBwW/15/

Click the button 'Range 50' and afterwords 'Range 20'. Then 'Range 50' again. You can see the color changing but not the range.

I tried hard to figure out how to fix this problem, but without success. I hope, somebody can help me.

<div id="container" style="height: 400px; min-width: 600px"></div>

<script src="http://code.highcharts.com/stock/highstock.js"></script>

<button id="button_20">Range 20</button>
<button id="button_50">Range 50</button>

$(function() {
$('#container').highcharts({  

    chart: {
    },

    rangeSelector: {
        enabled: false          
    },

    exporting: {
        enabled: false
    },

    title : {
        text : 'Ranges'
    },

    navigator: {
        enabled: true,
    },

    xAxis: {
        lineColor: '#ffcc00'
    },

    series : [{
        name : 'Random data',
        data : (function() {
            // generate an array of random data
            var data = [], i;
            for( i = 1; i <= 100; i++) {
                data.push([
                    i,
                    Math.round(Math.random() * 100)
                ]);
            }
            return data;
        })()
    }]

});

// the button action
$('#button_20').click(function() {
    var chart = $('#container').highcharts();
    chart.xAxis[0].update({
        lineColor: '#00ff00',           
        range: 20
    });     
});

$('#button_50').click(function() {
    var chart = $('#container').highcharts();
    chart.xAxis[0].update({
        lineColor: '#E22636',           
        range: 50
    });     
  });        
});

回答1:


Have you tried to use setExtremes() http://api.highcharts.com/highstock#xAxis.events.setExtremes which allow to define range.

EDIT: Example: http://jsfiddle.net/wkBwW/16/



来源:https://stackoverflow.com/questions/17291715/change-range-in-highstock-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!