【发布时间】:2013-06-07 03:33:57
【问题描述】:
我希望使用 jqplot 插件 (http://www.jqplot.com/tests/pie-donut-charts.php) 来生成饼图,但是我无法将 $get 函数的结果转换为 jqplot 函数将接受为可用数据的内容。
您可以在上面的 jqplot 链接中看到我需要如何创建数据变量来显示饼图。
这是我的 $.get 函数,它当前返回一个字符串:
//data is returned as a string: 'some_field_name',10,'some_other_field,33 etc
$.get("notesajax.php", {month:monthFilter, area:areaFilter}, function(data) {
var arr = data.split(",");
var results = [];
for (var i = 0; i < arr.length; i++) {
mini = [];
mini[arr[i]] = "'"+arr[i]+"',"+arr[i+1];
results.push(mini);
i++;
}
为了方便参考,这里是 jqplot 函数,在开始时包括一个定义的“数据”变量,以说明 jqplot 期望如何接收数据。
//this variable is just for illustrative purposes
var data = [
['Heavy Industry', 12],['Retail', 9], ['Light Industry', 14],
['Out of home', 16],['Commuting', 7], ['Orientation', 9]
];
var plot1 = jQuery.jqplot ('chartdiv', [results],
{
seriesDefaults:
{
// Make this a pie chart.
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
// Put data labels on the pie slices.
// By default, labels show the percentage of the slice.
showDataLabels: true
}
},
legend: { show:true, location: 'e' }
}
);
但到目前为止,我无法将我的 $get 返回数据转换为 jqplot 函数可以接受的格式。
【问题讨论】:
标签: javascript jquery multidimensional-array get