I need to change how the float pie legend appears, I need it to appear a label : percentage of the graph. so and to stay
code of js
(function( $ ) {
'use strict';
(function() {
var plot = $.plot('#flotPie', flotPieData, {
series: {
pie: {
show: true,
combine: {
color: '#999',
threshold: 0.1
},
}
},
legend: {
show: true,
},
grid: {
hoverable: true,
clickable: true
}
});
})();
}).apply( this, [ jQuery ]);
code of HTML
<div class="chart chart-sm" id="flotPie">
<script type="text/javascript">
var flotPieData = [{
label: "Otimo: ",
data: [
[1, 1]
],
color: '#0088cc'
}, {
label: "Bom:",
data: [
[1, 1]
],
color: '#2baab1'
}, {
label: "Regular:",
data: [
[1, 1]
],
color: '#734ba9'
}, {
label: "Ruim:",
data: [
[1, 1]
],
color: '#E36159'
}];
</script>
</div>
I'm using a template, where I pass this information, I thought of concatenating the label + percentage more how would you do that?
in order to show the percentage on the legend label,
you will need to calculate each percentage,
and modify the label accordingly,
before drawing the chart.
first, calculate the total. this is achieved by looping the data set and totaling the y-axis value of each series row.
next, the loop the data set again,
calculate the percentage,
and modify the label.
see following working snippet...