How to display percentage in Pie Chart for DIMPLE js

994 Views Asked by At

I'm using dimple js to draw a pie chart. I want to display the percentage in pie chart.

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

Below is the link for reference.

dimple js Pie Chart

1

There are 1 best solutions below

0
Roy Shilkrot On

Instead of addMeasureAxis use 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();    
});

Working jsfiddle: https://jsfiddle.net/d599brmy/