You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2020/05/21 05:18:33 UTC

[GitHub] [incubator-echarts] plainheart edited a comment on issue #12677: 饼图-传入数据后 是否可以返回每个数据的百分比

plainheart edited a comment on issue #12677:
URL: https://github.com/apache/incubator-echarts/issues/12677#issuecomment-631886102


   没有提供直接的API可以获取,不过要是真想获取也能计算得到。
   1、直接拿自己的原始数据,计算百分比。
   2、获取到你想要获取百分比的pie系列实例,根据其`layout`中的`angle`计算出对应角度,再除以`360`可以算出百分比。
   ```js
     var model = chart.getModel();
     // 根据索引获取系列,或者也可以根据名称、类型等获取
     var pieSeries = model.getSeriesByIndex(0); // getSeriesByName/getSeriesByType
     // 传入你想要获取的数据项索引,可以得到该数据项的Layout
     var itemLayout = b.getData().getItemLayout(0);
     // layout中有我们所需的angle数值,这是一个弧度值,可转换为角度除以360计算百分比
     // 或者直接除以 2*Math.PI计算百分比
     var percent = itemLayout.angle / (2 * Math.PI); // 或者180 / Math.PI * itemLayout.angle / 360
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org