[英]Highstock - Pulling data from JSON file
I understand there are many similar questions related to this topic on SO however, I was unsuccessful at implementing what I am trying to do so I am writing a question here. 我知道有很多与此主题相关的类似问题,因此,我没有实现我想做的事情,因此我在这里写了一个问题。 Please understand that I am very new. 请理解我很新。
So, basically, using the Highstock - the basic graph which can be found here http://www.highcharts.com/stock/demo/basic-line , I want to import the data from an JSON file named Json1.json. 因此,基本上,使用Highstock-基本图形(可在http://www.highcharts.com/stock/demo/basic-line上找到),我想从名为Json1.json的JSON文件中导入数据。 How would I do this? 我该怎么做? http://jsfiddle.net/x0g8hL0e/1/ http://jsfiddle.net/x0g8hL0e/1/
In the JavaScript, I have written 在JavaScript中,我写了
$(function () {
$.getJSON('Json1.json', function (data) {
// Create the chart
$('#container').highcharts('StockChart', {
rangeSelector : {
selected : 1
},
title : {
text : 'Pressure'
},
});
});
});
Also, is it possible to just see the 24 hour format instead of a year-long? 另外,是否可以只看24小时格式而不是一年?
PS, Json data is formatted in this way PS,Json数据以这种方式格式化
[
{"Pressure": 1},
{"Pressure": 5},
{"Pressure": 3},
{"Pressure": 2},
{"Pressure": 4}
}]
You should process your data, so it will be in a format that is accepted by Highcharts. 您应该处理您的数据,因此它将采用Highcharts接受的格式。 It can be (as described in API reference ): 可以是(如API参考中所述 ):
Other option is to use an array with keys
defined. 另一种选择是使用定义了keys
的数组。
If you want to use eg 1st data fromat, then you could go through your JSON and create an array of numerical values with values taken out of each object, from Pressure
property. 如果要使用例如fromat的第1个数据,则可以遍历JSON并创建一个数值数组,其中包含从Pressure
属性中获取的每个对象的值。
$(function () {
//$.getJSON('Json1.json', function (data) {
// simulate JSON data
var data = [{
"Pressure": 1
}, {
"Pressure": 5
}, {
"Pressure": 3
}, {
"Pressure": 2
}, {
"Pressure": 4
}],
processedData = [];
// process the data to match one of formats required by Highcharts - an array of numberical values
// see: http://api.highcharts.com/highstock#series<line>.data
Highcharts.each(data, function(d) {
processedData.push(d.Pressure);
});
// Create the chart
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 1
},
title: {
text: 'Pressure'
},
series: [{
data: processedData
}]
});
//});
});
For basic information about Highcharts you could see General Documentation 有关Highcharts的基本信息,请参阅常规文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.