how to calculate the angle between the mid of a clicked donut element and the negative y-axis

核能气质少年 提交于 2019-12-02 10:56:09

Here you can find my solution to your problem if I got you right.

$("#pie-placeholder").bind("plotclick", function(event, pos, obj) {
if (obj) {
    var percentInRads = 0.02;
    var currSegmentInRads = percentInRads * obj.datapoint[0]
    var currSegmentOffset = currSegmentInRads / 2;
    var currSegmentStart = currSegmentOffset >= 0.5 ? -0.5 + currSegmentOffset : 0.5 - currSegmentOffset;
    var total = 0;
    var beforeTotal = 0;

    for (var idx = 0; idx < data.length; idx++) {
      var segment = data[idx];

      if (idx < obj.seriesIndex) {
        beforeTotal += segment.data;
      }

      total += segment.data;
    }

    var beforePart = (beforeTotal / total * 100) * percentInRads;
    var chartStartAngle = currSegmentStart - beforePart;

    options.series.pie.startAngle = chartStartAngle;
    $.plot($("#pie-placeholder"), data, options);
    console.log(obj.series);
}

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