I have a controller that generates the following json data:
[
{
"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
}
]
I want to make a pie chart from this data using jqplot. I am able to make a chart by following a tutorial but i am not able to show the text labels with the slices. Here is my js code:
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);
});
});
please tell me how do i show the text associated with pie chart slices. I know i am missing something but again i am a newbie to javascript.
I have a controller that generates the following json data:
[
{
"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
}
]
I want to make a pie chart from this data using jqplot. I am able to make a chart by following a tutorial but i am not able to show the text labels with the slices. Here is my js code:
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);
});
});
please tell me how do i show the text associated with pie chart slices. I know i am missing something but again i am a newbie to javascript.
Share Improve this question edited Mar 13, 2012 at 12:39 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Mar 13, 2012 at 12:28 aliirzaliirz 1,0042 gold badges13 silver badges25 bronze badges1 Answer
Reset to default 4Your data structure is incorrect this link takes you to a working example.
jqPlot example
I think this will work
dataSlices.push([entry['title'], entry['votes']]);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744382111a4571482.html
评论列表(0条)