Javascript JSON数据的饼图
我有一个生成以下json数据的控制器:Javascript JSON数据的饼图,javascript,jquery,asp.net,asp.net-mvc-3,jqplot,Javascript,Jquery,Asp.net,Asp.net Mvc 3,Jqplot,我有一个生成以下json数据的控制器: [ { "title": "Option 0", "votes": 0 }, { "title": "Option 1", "votes": 1 }, { "title": "Option 2", "votes": 2 }, { "title": "Option 3", "
[
{
"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从这些数据制作一个饼图。我可以通过以下步骤制作图表,但我无法显示带有切片的文本标签。以下是我的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的新手。您的数据结构不正确。此链接将带您进入一个工作示例 我想这会管用的
dataSlices.push([entry['title'], entry['votes']]);
您的数据结构不正确此链接将带您到一个工作示例 我想这会管用的
dataSlices.push([entry['title'], entry['votes']]);