简体   繁体   English

高位图表-以编程方式设置切片的饼图时丢失的动画

[英]high charts - lost animation when pie chart sliced is programmatically set

As you can see from this basic example, http://www.highcharts.com/demo/pie-basic when you select a pie, the selected pie got pulled out slowly with animation. 从这个基本示例( http://www.highcharts.com/demo/pie-basic)中可以看到,当您选择一个饼图时,选定的饼图会随着动画缓慢拉出。 and that is handled by this option. 这由该选项处理。

pie: {
     allowPointSelect: true
}

However, I don't want mouse click to select Point. 但是,我不想单击鼠标以选择“点”。 I have, say, a button outside of the pie chart, when I press the button, the first pie/Point should be selected. 我在饼图外面有一个按钮,当我按下按钮时,应该选择第一个饼图/点。

I have the following 我有以下

$scope.SAWChartConfig.series[0].data[0].selected = true;
$scope.SAWChartConfig.series[0].data[0].sliced = true;

programatically set the first point as selected when button clicked. 单击按钮时,以编程方式将第一个点设置为选定的位置。 It works fine, but it lost the animation (where it should slowly pull outward). 它可以正常工作,但是丢失了动画(应该将动画缓慢向外拉出)。

My questions are: 我的问题是:

  1. how can i add the animation back? 如何添加回动画?
  2. series[0].data contains a few data points, I would need to reset data[i].sliced to false for each of them after button is clicked. series [0] .data包含几个数据点,单击按钮后,我需要将每个数据点[i] .sliced都设置为false。 Is there a easy way to do it instead of loop through all items? 有没有一种简单的方法可以代替遍历所有项目?

.controller('spendingPieChartCtrl', ['$scope', '$q', 'TransactionService', 'CategoryService','chartColors', function ($scope, $q, TransactionSvc, CategorySvc, chartColors) { if(typeof $scope.height === 'undefined') { $scope.height = 140; } $scope.SAWChartConfig = { options: { chart: { plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false, type: 'pie', margin: [0, 0, 0, 0], spacingTop: 0, spacingBottom: 0, spacingLeft: 0, spacingRight: 0, height: $scope.height }, plotOptions: { pie: { dataLabels: { enabled: false }, size: '100%', borderWidth: 0 }, series: { states: { hover: { enabled: false } } } }, title:{ text: null }, tooltip: { enabled: false } }, series: [{ data: [] }] }; .controller('spendingPieChartCtrl',['$ scope','$ q','TransactionService','CategoryService','chartColors',function($ scope,$ q,TransactionSvc,CategorySvc,chartColors){if(typeof $ scope .height ==='未定义'){$ scope.height = 140;} $ scope.SAWChartConfig = {选项:{图表:{plotBackgroundColor:null,plotBorderWidth:null,plotShadow:false,类型:'pie',边距: [0,0,0,0],spacespaceTop:0,spacespaceBottom:0,spacespaceLeft:0,spacespaceRight:0,高度:$ scope.height},plotOptions:{饼图:{dataLabels:{启用:false},大小: '100%',borderWidth:0},系列:{状态:{悬停:{启用:否}}}}},标题:{文本:空},工具提示:{启用:否}},系列:[{数据: []}]};

 $q.all([ TransactionSvc.get(), CategorySvc.get() ]).then(function() { var spendingCategories = TransactionSvc.getTopCategories(); //redraw the chart by updating series data $scope.SAWChartConfig.series = [{data: spendingCategories}]; }); $scope.$on('talkToOne', function( event, data ){ $scope.SAWChartConfig.series[0].data[index].select(); //$scope.SAWChartConfig.series[0].data[index].sliced = true; }); 

I am using ng-hightcharts, and here is the directive call 我正在使用ng-hightcharts,这是指令调用

chart.series[0].data[index].select() will do the select/deselect of the slices without loosing animation. chart.series[0].data[index].select()将选择/取消选择切片,而不会丢失动画。

See the working example here 这里查看工作示例

By using above code your second problem will also get fixed, since the next select call will automatically deselect other selected slices in the chart. 通过使用上述代码,您的第二个问题也将得到解决,因为下一个select调用将自动取消选择图表中的其他选定切片。

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

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