2017-09-21 97 views
0

我有一个动态创建的饼图,它使用下面描述的函数createPieChart()。当单击切片时,我想调用一个函数来打印出该切片的标签和值。QML Chart interactive

我面临两个问题:

  1. 虽然我连接“点击”或“按下”或“释放”信号,没有达到插槽。我正在使用qtcharts 2.0(我现在无法更新)。
  2. 我能够连接“徘徊”信号,但没有传递任何参数,所以我不知道我进入了什么切片。

这些都是其他功能:

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

显然我不是面临这个问题的唯一一个。 clicked()信号不在这篇文章中触发:https://stackoverflow.com/questions/40626911/why-is-the-clicked-signal-for-the-qpieslice-not-emitted – laurapons

回答

0

升级到2.2 QtCharts我能够解决像这样经过: 对于饼状&线&散点图,我使用onClicked,返回片/点。因此,在动态创建切片或点时,您不需要连接任何信号。

对于柱状图,我是能够连接barset创建

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)} 
}