我用 dc.js 构建了一个饼图,包含以下内容:
var chart = dc.pieChart(selector, this.chartGroup)
.width(200).height(200)
.dimension(this.dimension)
.group(this.group)
...
.legend(dc.legend().x(10).y(255).gap(5).horizontal(true))
chart.render()
有没有一种方法可以将图例上的标签格式化为如下所示:
function (d) {
return d.key + ': ' + d.value;
}
最佳答案
最后的答案似乎部分正确。我建议如下:
.legend(dc.legend().x(100).y(400).itemHeight(13).gap(5).autoItemWidth(true).legendText(function (d) {
return d.name + " " + Math.round((d.data / totalPrice) * 100) + "%"
}));
其中 d.name 是您将在图例中看到的实际标签。 d.data为实际值。
关于javascript - 在 dc.js 中更改图例值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22053959/