Highcharts getjson并动态更改系列类型

时间:2018-03-23 22:25:29

标签: javascript jquery highcharts

我不想改变系列类型,但是  有一个JavaScript控制台错误:  函数change_chart中的options.series为null ...

<script src="../code/highstock.js"></script>

<div id="container" style="height: 400px; min-width: 310px"></div>
        <script type="text/javascript">
    var chart;
    var options;

$(document).ready(function() {
    options = {
        chart: { renderTo: 'container'},
        rangeSelector: {selected: 1},
        title: { text: 'AAPL Stock Price'},

        series: [{
            type: 'candlestick',
            name: 'AAPL Stock Price11',
            dataGrouping: {
                units: [
                    [
                        'week', // unit name
                        [1] // allowed multiples
                    ], [
                        'month',
                        [1, 2, 3, 4, 6]
                    ]
                ]
            }
        }]    
    };

    chartfunc = function(type)
    {
        alert(options.series);      
        options.type = type;
        chart = new Highcharts.stockChart(options);
    }

    $.getJSON('http://localhost/highstock/data/aapl-ohlcv.json', function(data) {
        options.series[0].data = data;
        chart = new Highcharts.stockChart(options);
    });
});     
        </script>

我不明白为什么options.series“将自己”设置为null ...

1 个答案:

答案 0 :(得分:0)

我通过更改chartfunc来实现它:

chartfunc = function(type)
{
    chart.series[0].update({
        type: type
    });
}