它不适用于所有三种浏览器 - IE,Chrome和Firefox。
以下是我的HTML源代码:
<html>
<head>
<script type ="text/javascript" src ="jquery-1.10.2.js" ></script>
<script type ="text/javascript" src ="highcharts.js" ></script>
<script type ="text/javascript" src ="exporting.js" ></script>
<script type ="text/javascript" src ="fruits.js" ></script>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
</body>
</html>
这是我在fruits.js脚本中的源代码:
$(document).ready(function () {
var options = {
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text: 'Fruit Consumption'
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Units'
}
},
series: []
};
$.get('data.csv', function (data) {
// Split the lines
var lines = data.split('\n');
// Iterate over the lines and add categories or series
$.each(lines, function (lineNo, line) {
var items = line.split(',');
// header line containes categories
if (lineNo == 0) {
$.each(items, function (itemNo, item) {
if (itemNo > 0) options.xAxis.categories.push(item);
});
}
// the rest of the lines contain data with their name in the first
// position
else {
var series = {
data: []
};
$.each(items, function (itemNo, item) {
if (itemNo == 0) {
series.name = item;
} else {
series.data.push(parseFloat(item));
}
});
options.series.push(series);
}
});
// Create the chart
var chart = new Highcharts.Chart(options);
});
});
所以任何想法为什么不是图表显示任何东西?它确实可以在没有CSV数据文件的情况下工作
这就是我在csv文件中的内容:
Categories,Apples,Pears,Oranges,Bananas
John,8,4,6,5
Jane,3,4,2,3
Joe,86,76,79,77
Janet,3,16,13,15