我的服务器返回的 Json
{
"data": [{
"name": "name",
"data": ["[Date.UTC(2017, 01, 25), 89]",
"[Date.UTC(2017, 01, 26), 99]",
"[Date.UTC(2017, 02, 02), 106]",
"[Date.UTC(2017, 02, 04), 102]",
"[Date.UTC(2017, 02, 07), 110]",
"[Date.UTC(2017, 10, 31), 155]"]
}]
}
我使用的代码仅来 self 生成的数据(上图) https://www.highcharts.com/demo/spline-irregular-time
我的Javascript代码
Please Remove one T from bit ly
$.getJSON('http://bitt.ly/2zpoZqT', function (csv) {
console.log(csv['data']);
Highcharts.chart('container', {
chart: {
type: 'spline'
},
title: {
text: 'Keyword Tracking'
},
subtitle: {
text: 'Top 20 Keywords'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%e. %b',
year: '%b'
},
title: {
text: 'Date'
}
},
yAxis: {
title: {
text: 'Snow depth (m)'
},
min: 0
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x:%e. %b}: {point.y:.2f} m'
},
plotOptions: {
spline: {
marker: {
enabled: true
}
}
},
series: csv['data']
});
});
最佳答案
只需将良好的属性 series
添加到成功调用 $.getJSON
中的对象 json 返回中,就像您所做的那样。但本例根据脚本需要创建一个属性 series
,并将 data
的值影响
到 series
和 >删除数据
你就完成了。
$.getJSON('http://bitt.ly/2zpoZqT', function (csv) {
console.log(csv['data']);
csv.series = csv.data;//new attribute series affected to data
delete csv.data; //delete data to have the good object
Highcharts.chart('container', {
chart: {
type: 'spline'
},
title: {
text: 'Keyword Tracking'
},
subtitle: {
text: 'Top 20 Keywords'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%e. %b',
year: '%b'
},
title: {
text: 'Date'
}
},
yAxis: {
title: {
text: 'Snow depth (m)'
},
min: 0
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x:%e. %b}: {point.y:.2f} m'
},
plotOptions: {
spline: {
marker: {
enabled: true
}
}
},
series: csv['data']
});
});
关于javascript - HighCharts getJson - 无法显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47057730/