dc.js: Adding a Legend to Pie Chart

我的未来我决定 提交于 2020-02-23 04:05:00

问题


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;});

回答1:


The syntax looks correct.

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.

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

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.



来源:https://stackoverflow.com/questions/30041565/dc-js-adding-a-legend-to-pie-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!