Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flot pie chart label

flot pie chart shows the label of the items by default in percentage, but i need to show the number which make up the percent instead of the percentages. the code below is my data and

var pieOptions={
    series: {
        pie: {
            show: true,
            radius: 1,
            label: {
                show: true,
                radius: 3/4,
                formatter: labelFormatter,
                background: {
                    opacity: 0.5,
                    color: '#000'
                }
            }
        }
    },
    grid: {
        hoverable: true,
        clickable: true
    },
    legend: {
        container: '#pieLegend'
    }
}

the label formatter

function labelFormatter(label, series) {
    return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>"
+ label + "<br/>" + Math.round(series.percent) + "%</div>";
}

my data

[["ebbok1","1"],["ebook2","4"],["ebook3","4"],["something","3"]]

so i need 1,4,4,3 to show on the pie chart instead of the calculated percentages

Edit

i just tried series.data[0][1], but it showed blank in the chart

like image 926
Smith Avatar asked Feb 16 '23 10:02

Smith


1 Answers

Change the labelFormatter to:

function labelFormatter(label, series) {
    return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>"    + label + "<br/>" + series.data[0][1] + "%</div>";
}

That the y data of the first (only) point in the series.

like image 183
Mark Avatar answered Feb 28 '23 06:02

Mark