【问题标题】:flot pie chart label浮动饼图标签
【发布时间】:2013-08-30 04:36:10
【问题描述】:

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],但它在图表中显示为空白

【问题讨论】:

    标签: javascript formatting flot pie-chart


    【解决方案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 数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-01
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多