简体   繁体   English

flot饼图标签

[英]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. flot饼图默认以百分比显示项目的标签,但我需要显示构成百分比而不是百分比的数字。 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 所以我需要1,4,4,3来显示饼图而不是计算的百分比

Edit 编辑

i just tried series.data[0][1] , but it showed blank in the chart 我刚刚尝试过series.data[0][1] ,但它在图表中显示为空白

Change the labelFormatter to: 将labelFormatter更改为:

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. 即系列中第一个(唯一)点的y数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM