简体   繁体   English

使用highcharts-ng对饼图起始角度进行动画处理

[英]Animate change in piechart start angle with highcharts-ng

I'm using highcharts-ng to create a dynamically updated piechart. 我正在使用highcharts-ng创建动态更新的饼图。

When the data changes the slices animate (grow or shrink in size). 当数据更改时,切片将设置动画(大小增加或缩小)。 I am trying to achieve a similar effect with a regard to the start angle of the chart. 我试图在图表的起始角度上达到类似的效果。

When the startAngle property of a series changes I would like a transition animation to occur. 当系列的startAngle属性更改时,我希望发生过渡动画。 I don't know if this is possible. 我不知道这是否可能。

Here's a JSFiddle which shows the change in start angle, but without the animation. 这是一个JSFiddle,它显示了起始角度的变化,但是没有动画。

http://jsfiddle.net/367gjasq/2/ http://jsfiddle.net/367gjasq/2/

here's a snippet of code from the jsFiddle which shows how I'm currently updating the startAngle property of the chart 这是jsFiddle的代码片段,显示了我当前如何更新图表的startAngle属性

$scope.updateChartData = function() {
    //access to highcharts, though not using currently
    var h = $scope.chartConfig.getHighcharts();

    //register a change in series start angle
    $scope.chartConfig.series[1].startAngle += 20;

    //to make demo better, restart inner donut start angle
    if($scope.chartConfig.series[1].startAngle >= 0)
        $scope.chartConfig.series[1].startAngle = -360;

    //issue a digest so changes will reflect in chart
    $scope.$digest();
};

I was not able to find a way to animate a change in start angle of the series. 我无法找到一种方法来动画化系列开始角度的变化。

What I settled on instead was creating a 'ghost' element of the series. 相反,我决定在系列中创建一个“幽灵”元素。 Here is my series element object 这是我的系列元素对象

{
        name: 'empty',

        //make element transparent
        color: 'rgba(255, 255, 255, 0)',

        //cursor does not change on hover
        cursor: 'cursor',

       //so legend element won't disrupt actual legend display
       legendIndex: lastIndexOfLegend,

       // takes up the total size of 'empty space' required
        y: total - (aggregate)
      };

I also had to change my tooltip formatter to watch for a point with the 'key' of 'empty' 我还必须更改工具提示格式化程序,以注意带有“空”键的点

if(this.key === 'empty') 
   return;

So no tooltip would display on hover 因此悬停时不会显示任何工具提示

and in my legend formatter 在我的图例格式化程序中

if(this.name === 'empty')
  return '';

as returning nothing resolved to show undefined in the legend 不返回任何结果以显示图例中undefined的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM