Search code examples
javascriptjqueryjqplot

jqPlot Pie chart data label does not show


I have such pie chart
which has data labels with values ["", 20, 1, 3, "", "", "", "", 4, 6, 6], it shows all values without any problem, except that it doesn't show value 1. How can i fix it or is it jqPlot bug?

enter image description here

My code is:

function getPieChart(res) {
    var data = [];
    $.each(res, function (ind, resData) {
        data.push([resData.Stage, resData.Count]);
    });
    var dataLbl = [];
    for (var i = 0; i < data.length; i++) {
        if (data[i][1] != 0) {
            dataLbl.push(data[i][1]);
        }
        else {
            dataLbl.push('');
        }
    }
    var piePlot = jQuery.jqplot('pie-chart', [data],
      {
          seriesDefaults: {
              renderer: jQuery.jqplot.PieRenderer,
              rendererOptions: {
                  showDataLabels: true,
                  dataLabels: dataLbl,
                  diameter: 250,
                  dataLabelPositionFactor: 0.5,
                  sliceMargin: 3,
                  color: '#DCDCDC'
              },
              shadow: false
          }
      }
    );
}

Solution

  • i dont know whether you could solve this yet, but the problem is the dataLabelThreshold setting

    by default its value is 3, so nothing below this value will be shown

    try setting its value to zero (range is 0-100) like this

    rendererOptions: { 
       dataLabelThreshold: 0, 
       showDataLabels: true, 
       dataLabels: labels, 
       dataLabelFormatString: "%s" 
    }