Solved Custom Item controlling LineSeries
-
Hello all! I am wondering how could I correctly create my own ChartView drawer. What I mean: let suppose that we have some Item with ChartView with the following structure:
Item { ChartView { MyCustomItem { LineSeries {} LineSeries {} ScatterSeries {} function plot() {} } } }
I want to implement item with several series to be plotted on the parent's ChartView. In this was it is not working, looks like Series should be created inside ChartView. Moreover, if I understand correctly, Series don't have parents, so I could not change parent. In documentation I have not found how to attach already created Series to the ChartView. Is there some not so long way to do so, or should I redefine ChartView module?
I can create series dynamically in MyCustomItem:
Component.onCompleted: { if (parent instanceof ChartView) { scatterPoint = parent.createSeries(ChartView.SeriesTypeScatter, "scatter series", parent.axisX, parent.axisY); } }
Then I could use this scatterPoint as pointer and control this series. But can I connect this line properties dynamically with MyCustomItem properties?
-
Some workaround that I have found for my question: in c++ code I have implemented method:
void BaseChartView::setMainSeries(QAbstractSeries *abstractSeries) { if (abstractSeries == Q_NULLPTR) return; if (abstractSeries->type() == QtCharts::QAbstractBarSeries::SeriesTypeLine) m_mainSeries = static_cast<QLineSeries*>(abstractSeries); m_chart = m_mainSeries->chart(); }
Then I have created LineSeries on ChartView in qml code and used this method to receive pointer to QChart that I can successfully process later.
-
Some workaround that I have found for my question: in c++ code I have implemented method:
void BaseChartView::setMainSeries(QAbstractSeries *abstractSeries) { if (abstractSeries == Q_NULLPTR) return; if (abstractSeries->type() == QtCharts::QAbstractBarSeries::SeriesTypeLine) m_mainSeries = static_cast<QLineSeries*>(abstractSeries); m_chart = m_mainSeries->chart(); }
Then I have created LineSeries on ChartView in qml code and used this method to receive pointer to QChart that I can successfully process later.