dc.js 1.7中的饼图图例不显示 [英] Pie chart legend in dc.js 1.7 not showing up
问题描述
我想在dc.js中创建一个饼图图例。然而,没有传说。它只是...不显示。一切都与之前使用的图例命令相同。
I'm trying to create a pie chart legend in dc.js. However, there is no legend. It just... doesn't show up. Everything appears the same as before I used the legend command.
这里是图例代码:
.legend(dc.legend().x(80).y(70).itemHeight(13).gap(5));
以下是相关代码的其余部分:
Here is the rest of the relevant code:
var companyDimension = data.dimension(function(d) {return d.company;});
var totalSalesByCompany = companyDimension.group().reduceSum(function(d) {return d.total;});
var pieChartCompanySales = dc.pieChart("#pie-chart-sales-by-company");
pieChartCompanySales
.width(150).height(150)
.dimension(companyDimension)
.group(totalSalesByCompany)
.legend(dc.legend().x(80).y(70).itemHeight(13).gap(5));
dc.renderAll();
I'm getting my legend code from this tutorial, and it seems to check out with the official docs. What am I doing wrong?
推荐答案
我认为你没有做错什么。它的问题与您正在使用的dc.js的版本。请检查 http://jsbin.com/xasenusu/1/ 。我改变了dc.js的版本,并给了div一个更多的空间svg。
I think you are not doing anything wrong. Its the problem with the version of dc.js you are using. Please check http://jsbin.com/xasenusu/1/. I have changed the version of dc.js as well as gave the div a little more space to svg.
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.7/crossfilter.min.js"></script>
<script type="text/javascript" src="http://dc-js.github.io/dc.js/js/dc.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style>
#pie-chart-sales-by-company svg{width:350px;}</style>
</head>
<body>
<div id="pie-chart-sales-by-company"></div>
</body>
</html>
这篇关于dc.js 1.7中的饼图图例不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!