如何在饼图中显示DIMPLE js的百分比

时间:2014-11-26 06:06:25

标签: javascript d3.js dimple.js

使用简单的js绘制饼图。我想在饼图中显示百分比。

  var svg = dimple.newSvg("#chartContainer", 590, 400);    
d3.tsv("/data/example_data.tsv", function (data) {     
  var myChart = new dimple.chart(svg, data);    
  myChart.setBounds(20, 20, 460, 360);
  myChart.addMeasureAxis("p", "Unit ales");
  myChart.addSeries("Owner", dimple.plot.pie);
  myChart.addLegend(500, 20, 90, 300, "left");
  myChart.draw();    
});

以下是供参考的链接。

dimple js Pie Chart

1 个答案:

答案 0 :(得分:0)

而不是addMeasureAxis使用addPctAxis

var svg = dimple.newSvg("#chart", 590, 400);    
d3.tsv("https://raw.githubusercontent.com/PMSI-AlignAlytics/dimple/master/data/example_data.tsv", function (data) {     
  var myChart = new dimple.chart(svg, data);    
  myChart.setBounds(20, 20, 460, 360);
  myChart.addPctAxis("p", "Unit Sales");
  myChart.addSeries("Owner", dimple.plot.pie);
  myChart.addLegend(500, 20, 90, 300, "left");
  myChart.draw();    
});

工作jsfiddle:https://jsfiddle.net/d599brmy/