我已经使用sencha ExtJS网站中的饼图示例创建了饼图,我想为每个饼图片添加一个点击事件,以便处理上下文该片上的数据。我能够向馅饼添加点击侦听器,但不知道如何获取切片上的数据。ExtJS如何将点击事件添加到饼图片
以下是ExtJS代码。
Ext.onReady(function(){
var store = Ext.create('Ext.data.JsonStore', {
fields: ['name', 'data1', 'data2', 'data3', 'data4', 'data5'],
data: [{
'name': 'January',
'data1': 10
}, {
'name': 'February',
'data1': 7
}, {
'name': 'March',
'data1': 5
}, {
'name': 'April',
'data1': 2
}, {
'name': 'May',
'data1': 27
}]
});
Ext.create('Ext.chart.Chart', {
renderTo: Ext.getBody(),
width: 800,
height: 600,
animate: true,
store: store,
theme: 'Base:gradients',
legend: { // Pie Chart Legend Position
position: 'right'
},
series: [{
type: 'pie',
field: 'data1',
showInLegend: true,
tips: {
trackMouse: true,
width: 140,
height: 28,
renderer: function(storeItem, item){
//calculate and display percentage on hover
var total = 0;
store.each(function(rec){
total += rec.get('data1');
});
this.setTitle(storeItem.get('name') + ': ' + Math.round(storeItem.get('data1')/total * 100) + '%');
}
},
highlight: {
segment: {
margin: 5
}
},
label: {
field: 'name',
display: 'rotate',
contrast: true,
font: '18px Arial'
},
listeners: {//This Doesnt Work :(
itemclick: function(o){
alert('clicked at : ' + o);
}
}
}],
listeners: { //This Event handler works but I am not sure how to figure how which slice i have clicked ..................................
click: {
element: store, //bind to the underlying el property on the panel
fn: function(o, a){
alert('clicked' + o + a + this);
}
}
}
});
});
请帮忙。
问候, 拉利特
你是绝对正确的!我误解了这个问题。 – sra
非常感谢Abdel,它的工作,但我不明白为什么itemclick没有工作和itemmousedown事件的作品。你有关于这个文档的任何链接。 – Lalit
即使图表有itemclick事件。我没有在Series源代码中看到它。必须阅读更多的代码来回答你的问题。你可以从http://dev.sencha.com/deploy/ext-4.0.0/docs/api/Ext.chart.series.Series.html –