繁体   English   中英

flot饼图标签

[英]flot pie chart label

flot饼图默认以百分比显示项目的标签,但我需要显示构成百分比而不是百分比的数字。 下面的代码是我的数据和

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'
    }
}

标签格式化程序

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

我的数据

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

所以我需要1,4,4,3来显示饼图而不是计算的百分比

编辑

我刚刚尝试过series.data[0][1] ,但它在图表中显示为空白

将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>";
}

即系列中第一个(唯一)点的y数据。

暂无
暂无

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

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