elementClick事件在角度-nvd3图表中未触发
问题描述:
我正在使用Angular-nvd3来绘制饼图。elementClick事件在角度-nvd3图表中未触发
HTML
<nvd3 options="options.chart.options" data="options.chart.data" api="options.chart.api" config="config" events="events"></nvd3>
的Javascript
$scope.options.chart = {
options: {
chart: {
type: 'pieChart',
height: 500,
margin: {
top: 0,
right: 40,
bottom: 80,
left: 40
},
x: function(d) {
return d.key;
},
y: function(d) {
return d.y;
},
showLabels: true,
duration: 1500,
labelThreshold: 0.01,
showLegend: true,
lines: {
dispatch: {
elementClick: function(e) {
console.log('click')
},
elementMouseover: function(e) {
console.log('mouseover')
},
elementMouseout: function(e) {
console.log('mouseout')
}
}
}
}
},
data: [{
key: "One",
y: 5
}, {
key: "Two",
y: 2
}, {
key: "Three",
y: 9
}, {
key: "Four",
y: 7
}, {
key: "Five",
y: 4
}, {
key: "Six",
y: 3
}, {
key: "Seven",
y: .5
}],
api: {}
};
我需要调用一个事件,当馅饼用户点击chart.But上面的代码不行,请帮帮我?
答
基本上你在angularjs中使用第三方库是为了满足你的需求,所以对第三方的任何改变都应该反映在你自己的范围内,所以你应该使用$ scope。$ apply()。
elementClick: function(e) {
$scope.$apply();
console.log('click')
}
我希望这会帮助你。:)