0

以下代码显示一个空白图表(轴和标题显示正常但没有数据),我不明白为什么。这似乎不是数据格式问题,因为我遵循了文档。将选项记录到 Firebug 显示“系列”为空。

var chart1;
var data;

options = {
    chart: {
    renderTo: 'container',
        animation: Highcharts.svg,              
    },           
    rangeSelector: {
        enabled: true
    },
    navigator: {
        enabled: true
    },
    xAxis: {
        type: 'datetime'
    },
    yAxis: { //--- Primary yAxis
        title: {
            text: 'Volume'
        }
    },              
    series: [{
        name: 'name',
        step: true,
        data: data
    }]
};

console.log(options); //series is null here !

function readData() {
    //using foo data here, actually getting it via AJAX, and that works OK
    data = [[0,1],[1,2],[2,3]];
    alert("data created");

    //this checks that the data loaded OK
    document.getElementById("result").innerHTML = "";

    for (var i = 0; i < data.length; i++) {
        document.getElementById("result").innerHTML += 'Key: ' + data[i][0] + '; Value: ' + data[i][1] + "<br />";
    }
    chart1 = new Highcharts.StockChart(options);
}

这是我包括的内容:

<head>
    <title>Title</title>
    <meta charset="UTF-8">
    <script type="text/javascript" src="XHR.js"></script><!-- unrelated (for ajax) -->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
    <script src="http://code.highcharts.com/stock/highstock.js" type="text/javascript"></script>
    <script src="http://code.highcharts.com/stock/modules/exporting.js" type="text/javascript"></script>
    <script type="text/javascript"> ... </script>
</head>
4

1 回答 1

0

当然 data 为空,因为您没有将其分配给选项,请添加以下行:

options.series[0].data = data; 

来自 AJAX 的数据到来之后。例如,在您创建图表 ( chart1 = ...) 之前。

于 2013-07-08T12:25:48.997 回答