正如您从这个基本示例中看到的那样,http://www.highcharts.com/demo/pie-basic当您选择饼图时,所选饼图会随着动画慢慢拉出 . 这是由这个选项处理的 .
pie: {
allowPointSelect: true
}
但是,我不希望鼠标单击选择点 . 我有一个饼图外面的按钮,当我按下按钮时,应该选择第一个饼/点 .
我有以下内容
$scope.SAWChartConfig.series[0].data[0].selected = true;
$scope.SAWChartConfig.series[0].data[0].sliced = true;
按钮单击时以编程方式将第一个点设置为选中 . 它工作正常,但它失去了动画(它应该慢慢向外拉) .
我的问题是:
-
如何添加动画?
-
series [0] .data包含一些数据点,我需要在点击按钮后将数据[i] .sliced重置为false . 有没有一种简单的方法可以做到而不是遍历所有项目?
.controller('spendPieChartCtrl',['$ scope','$ q','TransactionService','CategoryService','chartColors',函数($ 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 :[]}]}; $ q.all([
TransactionSvc.get()
CategorySvc.get()
]) . then(function(){
var expenditureCategories = TransactionSvc.getTopCategories();
//通过更新系列数据重绘图表
$ scope.SAWChartConfig.series = [{data:spendCategories}];
});
$ scope . $ on('talkToOne',function(event,data){
$ scope.SAWChartConfig.series [0] . 数据[指数] . 选择();
//$scope.SAWChartConfig.series[0].data[index].sliced = true;
});
我正在使用ng-hightcharts,这是指令调用
1 回答
chart.series[0].data[index].select()
将执行切片的选择/取消选择而不会丢失动画 .查看工作示例here
通过使用上面的代码,您的第二个问题也将得到修复,因为下一个选择调用将自动取消选择图表中的其他选定切片 .