I created a program that reads stock data (time series) from the internet and displays it in a QML ChartView. After I add all the line series that I want, I can delete them by clicking a button.
I would like to know if it is possible to delete the line series by clicking at ANY point in the line series?
I am adding the series dynamically like this:
// stockID is sent from C++ when the timeSeriesReady signal is emitted
var chartViewSeries = chartView.createSeries(ChartView.SeriesTypeLine, stockID, dateTimeAxis_chartView_xAxis, valueAxis_chartView_yAxis);
// Set chartViewSeries (AbstractSeries/LineSeries) properties
chartViewSeries.onClicked.connect(lineSeriesClicked);
chartViewSeries.onHovered.connect(lineSeriesHovered);
stockChart.setLineSeries(chartViewSeries);
I don't want to crowd too much my post so I won't post ALL the files, however:
- dateTimeAxis_chartView_xAxis is a DateTimeAxis QML type inside the main ChartView QML typ with id: chartView
- valueAxis_chartView_yAxis is a ValueAxis QML type inside the main ChartView QML typ with id: chartView
- stockChart is the id of a StockChart QML Type imported from C++
lineSeriesClicked is this function:
function lineSeriesClicked(lineSeriesPoint){ console.log(lineSeriesPoint); }
lineSeriesHovered is this function:
function lineSeriesHovered(lineSeriesPoint, isHovered){ if(isHovered){ var date = new Date(lineSeriesPoint.x); console.log(date.getFullYear() + "-" + (((date.getMonth()+1) < 10) ? ("0" + (date.getMonth()+1).toString()) : (date.getMonth()+1)) + "-" + (((date.getDate()) < 10) ? ("0" + (date.getDate()).toString()) : (date.getDate())) + " -> " + lineSeriesPoint.y); } }
Now, in the log I see all the correct data, e.g., when hovered:
qml: 2017-08-29 -> 64.91115963918442
when clicked:
qml: QPointF(1.50432e+12, 65.0453)
Looking at XYSeries QML Type (https://doc.qt.io/qt-5/qml-qtcharts-xyseries.html#clicked-signal), the clicked signal that I am using only passes the a point.
Is there any way to get the name of the line series where the point data was obtained to be able to delete this series? Perhaps through some sort of context access or "this" keyword?
Thank you very much!!!