Creating an incomplete pie chart in Dimple.JS

六月ゝ 毕业季﹏ 提交于 2019-12-12 05:30:06

问题


I have a pie chart that needs to have a missing 10% missing slice. I have the following code but the pie is always 100%.

        var myChart = new dimple.chart(svg, data);
        myChart.setBounds(50, 50, 180, 180);
        myChart.defaultColors = chartOptions.colors;
        myChart.data.startAngle = 0;
        myChart.data.endAngle = (2 * Math.PI * 0.9);

        myAxis = myChart.addMeasureAxis('p', 'amount');

        var mySeries = myChart.addSeries('legend', dimple.plot.pie);

How do I make the pie less than 100%? The above example needs to have the pe be 90 percent.


回答1:


The only way I can see to hack this into dimple.js is with a fake datapoint, you hide after the draw:

<!DOCTYPE html>
<html>

<head>
  <script data-require="d3@3.4.6" data-semver="3.4.6" src="//cdnjs.cloudflare.com/ajax/libs/d3/3.4.6/d3.min.js"></script>
  <script data-require="dimplejs@2.1.2" data-semver="2.1.2" src="//cdnjs.cloudflare.com/ajax/libs/dimple/2.1.2/dimple.latest.min.js"></script>
</head>

<body>
  <script>
  
    var svg = d3.select('body')
      .append('svg')
      .attr('width', 500)
      .attr('height', 500);
  
    var data = [
      { "legend":"one", "amount": 2000 },
      { "legend":"two", "amount": 2000 * 0.10 }
    ];

    var myChart = new dimple.chart(svg, data);
    myChart.setBounds(50, 50, 180, 180);
    myAxis = myChart.addMeasureAxis('p', 'amount');
    var mySeries = myChart.addSeries('legend', dimple.plot.pie);

    myChart.draw();
    
    d3.select(".dimple-two")
      .style("display", "none");
      
  </script>
</body>

</html>


来源:https://stackoverflow.com/questions/45383257/creating-an-incomplete-pie-chart-in-dimple-js

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