我目前是第一次使用 jqPlot,发现很难找到有关如何设置条形图控件的任何信息。到目前为止,我已经能够设置折线图和饼图示例,但条形图难住了我。
public ActionResult PieChart()
{
return View();
}
public ActionResult PieChartJSON()
{
List<PieChartData> sampleData = new List<PieChartData>();
PieChartData test = new PieChartData();
PieChartData test2 = new PieChartData();
PieChartData test3 = new PieChartData();
PieChartData test4 = new PieChartData();
PieChartData test5 = new PieChartData();
test.Label = "tara";
test.Value = 3;
sampleData.Add(test);
test2.Label = "becky";
test2.Value = 5;
sampleData.Add(test2);
test3.Label = "gareth";
test3.Value = 3;
sampleData.Add(test3);
test4.Label = "mark";
test4.Value = 8;
sampleData.Add(test4);
test5.Label = "james";
test5.Value = 8;
sampleData.Add(test5);
return Json(sampleData, JsonRequestBehavior.AllowGet);
}
这是我创建的饼图的示例。如果可能的话,有人可以给我一个应该如何格式化条形图 JSON 数据的示例吗?
这是正在输入 JSON 数据的视图:
jQuery(document).ready(function () {
urlDataJSON = '/Home/PieChartJSON';
$.getJSON(urlDataJSON, "", function (data) {
var dataSlices = [];
var dataLabels = "";
$.each(data, function (entryindex, entry) {
dataSlices.push(entry['Value']);
dataLabels = dataLabels + entry['Label'];
});
options = {
legend: { show: true },
title: 'Poll 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
}
}
}
var plot = $.jqplot('pieChart', [dataSlices], options);
});
});
这是我在网页上得到的图表:
编辑:嵌入屏幕截图不起作用。所以我会附上它的链接。 http://imgur.com/xwo3E