我会说它之前有效。现在,我已经更新了最新的Highcharts版本。并且,不知道为什么,它突然想要绝对显示我的CSV文件的第一个“列”。它看起来像这样:
,Switzerland,Europe,Global
1980,0.02854,0.01931,0.00547
1981,0.02898,0.01931,0.00549
Highcharts(“我的代码”)想要显示这个“”列。如果我将其更改为“年”或“类别”,它们都是一样的。我没有三个,但在传奇中有四个条目。
Highcharts代码如下所示:
// Split the lines
var lines = data.split('\n');
$.each(lines, function(lineNo, line)
{
var items = line.split(',');
// header line containes series name
if (lineNo === 0)
{
$.each(items, function(itemNo, item)
{
if (item!='')
{
if(item == 'Switzerland')
{
options.series.push(
{
name:item,
lineWidth: 5,
data:[]
});
}
else
{
options.series.push(
{
name:item,
data:[]
});
}
}
});
}
....
我试图改变这条线
if (item!='')
类似
if ((item!='') && (item!=' '))
或
if ((item!='') && (item!='Years'))
(当我在CSV文件的第一位添加“年”时),但我只收到错误消息...
感谢任何提示!
答案 0 :(得分:0)
我从过去发现了类似的例子,问题仅在于索引,它在推送点到系列期间使用。 解析器:
var options = {
chart: {
renderTo: 'container',
zoomType:'xy'
},
xAxis:{
categories:[],
tickInterval:10,
tickmarkPlacement:'on'
},
title: {
text: 'Oviedo hoy'
},
series: []
};
$.get('data.csv', function(data) {
// Split the lines
var lines = data.split('\n');
$.each(lines, function(lineNo, line) {
var items = line.split(',');
// header line containes series name
if (lineNo === 0) {
$.each(items, function(itemNo, item) {
if(item!='')
{
options.series.push({
name:item,
data:[]
});
}
});
}
// the rest of the lines contain data with their name in the first position
else {
console.log(options.series);
$.each(items, function(itemNo, item) {
if(itemNo == 0)
options.xAxis.categories.push(item)
else
options.series[itemNo-1].data.push(parseFloat(item));
});
}
});
var chart = new Highcharts.Chart(options);
});
答案 1 :(得分:0)
经过一番来回,以下是现在的工作原理:
$.get('data.csv', function(data)
{
// Split the lines
var lines = data.split('\n');
$.each(lines, function(lineNo, line)
{
var items = line.split(',');
// header line containes series name
if (lineNo === 0)
{
$.each(items, function(itemNo, item)
{
if (itemNo > 0)
{
if(item == 'Switzerland')
{
options.series.push(
{
name:item,
lineWidth: 5,
data:[]
});
}
else
{
options.series.push(
{
name:item,
data:[]
});
}
}
});
}
// the rest of the lines contain data with their name in the first position
else
{
$.each(items, function(itemNo, item)
{
if(itemNo == 0)
{
options.xAxis.categories.push(item);
}
else if (item == "null")
{
options.series[itemNo-1].data.push(null);
}
else
{
options.series[itemNo-1].data.push(parseFloat(item));
}
});
}
});
//console.log(options.series);
var chart = new Highcharts.Chart(options);
});
});