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