Search code examples
jqueryflotpie-chart

Flot Pie chart with legend & Pie labels


I am using flot library to draw pie chart. I want to draw pie chart having combination of legend & pie labels. Wherein pie labels will only display slice percentage & corresponding label information from data series will be displayed in legend. Is this combination possible using flot charts?


Solution

  • If you want the slices with percent only (no label), you need to define a custom formatter for the label option:

    $.plot($("#placeholder"), datapie, { 
        series: {
             pie: {
                 show: true,
                 label: {
                     show: true,
                     // Added custom formatter here...
                     formatter: function(label,point){
                         return(point.percent.toFixed(2) + '%');
                     }
                 }
            }
        },        
        legend: {show: true}
    });
    

    Fiddle here.

    enter image description here