大家好,我正在使用 JQPlot 来显示饼图。我是 Jquery 的新手,这就是为什么我很难在 Jquery 中操作数组。
这是将传递给 Jquery 的数组结构,它是动态的
array (size=8)
0 =>
array (size=1)
'Baseball' => string '12.18' (length=5)
1 =>
array (size=1)
'Basketball' => string '8.12' (length=4)
2 =>
array (size=1)
'Boxing' => string '5.54' (length=4)
3 =>
array (size=1)
'Golf' => string '6.64' (length=4)
4 =>
array (size=1)
'Soccer' => string '36.90' (length=5)
5 =>
array (size=1)
'Tennis' => string '27.31' (length=5)
6 =>
array (size=1)
'Football' => string '2.21' (length=4)
7 =>
array (size=1)
'Hockey' => string '1.11' (length=4)
我希望这些数据显示在我的饼图上。到目前为止,这是我的代码。
$(document).ready(function(){
var sports = $('#sports').val();
// sports - this variable holds the data array
jQuery.jqplot.config.enablePlugins = true;
plot1 = jQuery.jqplot('chart1',[sports],
[[['Verwerkende FruedenStunde Companaziert Eine industrie', 9],['Retail', 8], ['Primaire producent', 7],
['Out of home', 6],['Groothandel', 5], ['Grondstof', 4], ['Consument', 3], ['Bewerkende industrie', 2]]], `
// this is where i put the data from array but idont know how`
{
title: '',
seriesDefaults: {
shadow: false,
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: { padding: 2, sliceMargin: 2, showDataLabels: true }
},
legend: { show:true, location: 'w' }
});
});