将CSV加载到highcharts时遇到问题。我不知道如何做到这样:http://jsfiddle.net/3bQne/885/(我的代码基于:How do I select which columns from my CSV to chart with HighChart?)。这是我的样本CSV:
1,24,38
3,26,62
4,16,42
5,17,36
这是代码,应该在网页上显示我的图表:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" style="width:100%; height:400px;"></div>
<script>
var options = {
chart: {
renderTo: 'container',
defaultSeriesType: 'line'
},
title: {
text: 'Temperatura'
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'temperatura'
}
},
series: [{
data: []
}]
};
$.get('data.csv', function(data) {
var lines = data.split('\n');
$.each(lines, function (lineNo, line) {
var items = lines.split(',');
if(lineNo !== 0) {
var x = items[0];
temp = parseFloat(items[1]);
if(!isNaN(temp)){
options.series[0].data.push([x,temp]);
}
}
});
});
new Highcharts.Chart(options);
</script>
我整天都在努力制作一个让我感兴趣的图表,我只有这个...感谢您的帮助!