我有以下方式提供数据的文本文件
PC.json
[{“Category_B”:[2,0.5,2.5],“numpoints”:[3.2,4.5,0.5],“windspeed”:[。5,5.1,.1], “权力”:[0.0,2.5,3.2]},{“Category_B”:[3,1.5,2],“numpoints”:[1.2,2.5,0.5],“windspeed”:[1.5,4.1,2.1], “权力”:[0.5,2.5,3.2]},{“Category_B”:[1,2.5,1],“numpoints”:[2.2,3.5,1.5],“windspeed”:[1.5,3.1,2.5], “权力”:[4.5,5.5,3.5]}, {“Category_B”:[3,1.5,2],“numpoints”:[1.2,2.5,0.5],“windspeed”:[1.5,4.1,2.1], “权力”:[0.5,1.5,2.2]}
.....
...
这是jquery代码
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 155
},
title: {
text: 'Power',
x: -20 //center
},
yAxis: {
title: {
text: 'Kh'
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: []
}
$.getJSON("PC.json", function(json)
{
var len = json.length
var i=0;
for(i=0;i<len;i++){
var x= "POWER";
var y= json[i]['power'];
if(i==0){
options.xAxis.categories = x;
}else{
alert("X==== " + x + " and Y==== " + y); //able to get the power values
// j = i-1;
options.series[i] = y;
}
}
chart = new Highcharts.Chart(options);
});
});
如何获得功率值和风速值并将其绘制为高线图中的2线图?
答案 0 :(得分:1)
Txt文件不是JSON,因此无法正常工作,您是否可以返回文件返回后端为json / js / csv / xml?