【发布时间】:2012-03-13 12:28:37
【问题描述】:
我有一个生成以下 json 数据的控制器:
[
{
"title": "Option 0",
"votes": 0
},
{
"title": "Option 1",
"votes": 1
},
{
"title": "Option 2",
"votes": 2
},
{
"title": "Option 3",
"votes": 3
},
{
"title": "Option 4",
"votes": 4
},
{
"title": "Option 5",
"votes": 5
},
{
"title": "Option 6",
"votes": 6
},
{
"title": "Option 7",
"votes": 7
},
{
"title": "Option 8",
"votes": 8
},
{
"title": "Option 9",
"votes": 9
}
]
我想使用 jqplot 从这些数据中制作一个饼图。我可以按照tutorial 制作图表,但我无法显示带有切片的文本标签。这是我的js代码:
jQuery(document).ready(function () {
urlDataJSON = '/Poll/PollData?pollId=3';
$.getJSON(urlDataJSON, "", function (data) {
var dataSlices = [];
var dataLabels = "";
$.each(data, function (entryindex, entry) {
dataSlices.push(entry['votes']);
dataLabels = dataLabels + entry['title'];
});
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('chartdiv', [dataSlices], options);
});
});
请告诉我如何显示与饼图切片相关的文本。我知道我遗漏了一些东西,但我还是 javascript 的新手。
【问题讨论】:
标签: javascript jquery asp.net asp.net-mvc-3 jqplot