我有一个动态创建的饼图,它使用下面描述的函数createPieChart()。单击切片时,我想调用一个函数来打印出该切片的标签和值。
我面临两个问题:
这些是其他功能:
function createPieChart(data){
pieserieschart.clear();
slices.splice(0, slices.length) //clear slices array
for (var prop in data) {
slices.unshift(pieserieschart.append(prop, data[prop]));
//I get "Cannot read property 'label' of undefined using this method
slices[0].hovered.connect(function(){mouseHoverSlice(slices[0].label));
//WORKS, but I want to pass the label of that slice (and the value if possible)
slices[0].hovered.connect(mouseHoverSlice);
//it is not working at all
slices[i].clicked.connect(sliceClicked);
}
function sliceClicked(){
console.log("Slice Clicked"); //I cannot see this printed
}
function mouseHoverSlice(info){
console.log("Slice hover: " + info);
}
知道怎么做吗?谢谢!
答案 0 :(得分:1)
升级到QtCharts 2.2后,我能够像这样解决它: 对于馅饼&线和&散点图,我使用了onClicked,它返回切片/点。因此,在动态创建切片或点时,您无需连接任何信号。
对于条形图,我能够连接创建的小册子
var barvalues = barserieschart.append("label",values)
barvalues.clicked.connect(barClicked)
...
ChartView {
PieSeries {id: pieserieschart; onClicked: sliceClicked(slice) }
BarSeries {id: barserieschart }
ScatterSeries{id: scatterserieschart; onClicked: scatterclicked(point)}
}