我想在组合highCharts中传递数据。它有一个馅饼和一个样条。我已成功将数据传递给饼图,但我无法将数据传递给样条线。我哪里出错?
这是我的代码。
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript">
var spline_data = [{ // this value is to be passed downwards.
'name': 'Bangalore',
'data': [
[1383741000000, 1608.3000000000002], //[time in secs since 1970, value to be plotted against the time.]
[1383741900000, 1611.9999999999973],
[1383742800000, 1612.299999999997]
]
}, {
'name': 'New Delhi',
'data': [
[1383741000000, 54.2],
[1383741900000, 54.300000000000004],
[1383742800000, 54.300000000000004]
]
}];
var pie_data = [
['Firefox', 45.0],
['IE', 26.8],
['Chrome', 12.8],
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
$(function () {
$("#container").highcharts({
chart: {
height : 300,
backgroundColor : '#fafafa',
},
title: {
text: 'Energy Chart'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%e. %b',
year: '%b'
}
},
tooltip: {
formatter: function() {
var s;
s = this.y + 'kWh';
return s;
}
},
series: [{
type: 'spline',
data: spline_data,
showInLegend: true,
}, {
type: 'pie',
data: pie_data,
center: [90, 20],
size: 100,
cursor: 'pointer',
showInLegend: true,
dataLabels: {
enabled: false,
},
point :{
events:{
click : function(){
level_id = level_id + 1;
var pie_selected_location = this.name;
$.ajax({
dataType: "json",
type : 'POST',
url : '/dashboard/',
data : {'pie_selected_location': pie_selected_location, 'level_id' : level_id},
success: function(result){
comparison_chart(result,level_id);
}
});
}
}
},
}]
});
});
</script>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
</body>
</html>
这是我的jsFiddle
答案 0 :(得分:3)
这里您将整个spline_data作为一个数据集传递,而它代表2个样条线。
series: [{
type: 'spline',
data: spline_data[0].data,
showInLegend: true,
},{
type: 'spline',
data: spline_data[1].data,
showInLegend: true,
}
我在http://jsfiddle.net/5qhx3/1/
更新了你的小提琴希望这会对你有所帮助