Flot饼图标签

4

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]",但在图表中显示为空白。
1个回答

8

将 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值。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接