dc.js:向饼图添加图例 [英] dc.js: Adding a Legend to Pie Chart
问题描述
我正在尝试在我的饼图中添加一个图例,但我一直收到错误 TypeError:dc.legend不是函数
。
I'm trying to add a legend to my pie chart but I keep getting the error TypeError: dc.legend is not a function
.
我不知道从哪里开始修复此问题。我已经尝试过这个解决方案这里和在哪里,但没有运气。
I'm not sure where to begin on fixing this. I've tried the solution here and here, but no luck.
任何帮助将不胜感激!
Any help would be greatly appreciated!
var geoValue = facts.dimension(function (d) {
return d.geo;
});
var geoGroup = geoValue.group();
geoChart
.width(480)
.radius(100)
.innerRadius(90)
.dimension(geoValue)
.group(geoGroup)
.transitionDuration(500)
.legend(dc.legend().x(250).y(100)) //LEGEND CODE
.title(function(d){return d.geo;});
推荐答案
语法看起来正确。
我有几个案例,我的传奇也没出现过。这通常是因为我在图表的容器大小之外指定了.x()或.y()。首先将图例放在.x(0).y(0)以确保它适合容器内。
I have had several cases where my legend did not show up either. It was usually because I specified .x() or .y() outside the container size of the graph. Start by putting the legend at .x(0).y(0) to make sure it fits inside the container.
基本.legend()的工作小提琴对于pieChart可以在这里找到 http://jsfiddle.net/za8ksj45/39/
A working fiddle of the basic .legend() for the pieChart can be found here http://jsfiddle.net/za8ksj45/39/
Working example of original .legend(): line 1018
Working example of new .legend2(): line 1030
它有点冗长,因为该示例包含对该部分开头的legend.js的修改添加(%)到它。如果您只需要标准图例,请查看第1018行。
It is a bit lengthy because the example includes a modification to legend.js in the beginning of the section that lets you add (%) to it. If you just need the standard legend, look at line 1018.
这篇关于dc.js:向饼图添加图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!