简体   繁体   English

用于Highcharts的YQL金融数据JSON格式

[英]YQL finance data JSON format for use with highcharts

Im using jQuery and highcharts.js to build a single line chart on my webpage that shows historical financial data for whatever company the user requests. 我使用jQuery和highcharts.js在我的网页上构建了一个折线图,该折线图显示了用户要求的任何公司的历史财务数据。 I have been playing around with YQL and used this statement to retrieve some quotes in JSON format: 我一直在玩YQL,并使用此语句来检索JSON格式的一些引号:

select * from yahoo.finance.historicaldata where symbol = "AAPL" and startDate = "2013-02-01" and endDate = "2013-02-25" 从yahoo.finance.historicaldata中选择*,其中symbol =“ AAPL”且startDate =“ 2013-02-01”和endDate =“ 2013-02-25”

Heres a link to the YQL console with my query: 这是我的查询的YQL控制台链接:

http://developer.yahoo.com/yql/console/?q=show%20tables&env=store://datatables.org/alltableswithkeys#h=select%20 *%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22AAPL%22%20and%20startDate%20%3D%20%222013-02-01%22%20and%20endDate%20%3D%20%222013-02-25%22 http://developer.yahoo.com/yql/console/?q=show%20tables&env=store://datatables.org/alltableswithkeys#h=select%20 *%20from%20yahoo.finance.historicaldata%20where%20symbol% 20%3D%20%22AAPL%22%20and%20startDate%20%3D%20%222013-02-01%22%20and%20endDate%20%3D%20%222013-02-25%22

It returns a bunch of info about execution-start-time and exection-end-time and then at the end it gives me the quotes im after: 它返回一堆有关执行开始时间和执行结束时间的信息,然后最后它给我引号im:

"results": {
"quote": [
{
 "date": "2013-02-25",
 "Date": "2013-02-25",
 "Open": "453.85",
 "High": "455.12",
 "Low": "442.57",
 "Close": "442.80",
 "Volume": "13306400",
 "Adj_Close": "442.80"
},

Im having trouble extracting the Close price information from the results, ive tried the following code but im having trouble. 我在从结果中提取收盘价信息时遇到麻烦,我尝试了以下代码,但我遇到了麻烦。

    $.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22AAPL%22%20and%20startDate%20%3D%20%222013-02-01%22%20and%20endDate%20%3D%20%222013-02-25%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=cbfunc', function(data){

    console.log(data);

    var close = data.query.results.quote.close;
    document.write(close);

})

Can somebody tell me where im going wrong as I am new to jquery, yql and json. 有人可以告诉我我错在哪里吗,因为我是jquery,yql和json的新手。

Thanks 谢谢

It looks to me like the returned quote object is an array ? 在我看来,返回的报价对象是一个数组? Have you tried 你有没有尝试过

var close = data.query.results.quote[0].Close;
document.write(close);

If not, try setting a breakpoint on that line and examine the data object (eg in firebug). 如果不是,请尝试在该行上设置断点并检查数据对象(例如,在Firebug中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM