问题:我正在成功查询Yahoo Finance API,我想将一个多维数组输出到Highstock图表。但是,数据仅在导航器中呈现,而不是某些缩放级别的主图表。
问题:有人可以告诉我哪里出错了,还是这个错误?
注意:Highstocks期望这样的数据在series.data:http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?
这是一个现场演示:http://stevebrown.co/highstock/
var quoteData = [];
$(function() {
var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22YHOO%22%20and%20startDate%20%3D%20%222009-09-11%22%20and%20endDate%20%3D%20%222010-03-10%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=";
$.getJSON(url, function(
$.each(data.query.results.quote, function(index, value) {
var theTime = value.Date;
var milliTime = new Date(theTime);
milliTime = milliTime.getTime();
var results = [milliTime, parseFloat(value.Low), parseFloat(value.High)];
quoteData.push(results);
})
});
setTimeout("createChart()", 1000);
});
function createChart() {
console.log('quoteData', quoteData);
// Create the chart
window.chart = new Highcharts.StockChart({
chart : {
renderTo : 'container'
},
rangeSelector : {
selected : 1
},
title : {
text : 'AAPL Stock Price'
},
series : [{
name : 'AAPL',
data : quoteData,
tooltip: {
valueDecimals: 2
}
}]
});
}
答案 0 :(得分:1)
问题是您的期限从2010-03-10
到2009-09-11
,应该是2009-09-11
到2010-03-10
。
所以,你只需要反转你的数据阵列
以下行将解决问题。
quoteData = quoteData.reverse();