Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

qt chart "Can not add series. Series already on the chart."



  • QChart* QTemperatureChart::createSplineChart()
    {
    	m_pChart = new QChart();
    	m_pChart->setTitle("Spline chart");
    
    	// The lower series initialized to zero values
    	QString name("Series ");
    	int nameIndex = 0;
    
    	m_pSplineSeries = new QSplineSeries(m_pChart);
    	
    	m_pChart->addSeries(m_pSplineSeries);
    	m_pChart->createDefaultAxes();
    	m_pChart->axes(Qt::Vertical).first()->setRange(0, 10);
    
    	return m_pChart;
    }
    
    void QTemperatureChart::UpdateChart(QPointF point)
    {
    	int randomx = QRandomGenerator::global()->bounded(0, 100);
    	int randomy = QRandomGenerator::global()->bounded(0,100);
    	
    	//QSplineSeries series(m_pChart);
    	m_pSplineSeries->append(m_pSplineSeries->count(), randomy);
    	m_pChart->addSeries(m_pSplineSeries);
    	m_pChart->axisX()->setRange(0, m_pSplineSeries->count());
    	m_pChart->axisY()->setRange(0, 100);
    
    	qDebug() << "UpdateChart(QPointF point) : " << m_pSplineSeries->count();
    	m_pChartViewer->update();
    }
    

    I was trying to draw a chart, and there was a problem, and I wanted to find out how to solve it.

    If you append and add a series to update the chart in real time...
    "Can not add series. Series ready on the chart."
    If you add series again after the removeSeries, the chart looks weird.

    Let me know if there's any problem with my code.


  • Lifetime Qt Champion

    @IknowQT said in qt chart "Can not add series. Series already on the chart.":

    m_pChart->addSeries(m_pSplineSeries);

    Why do you add same series again? Just append new values to the series...


  • Lifetime Qt Champion

    @IknowQT said in qt chart "Can not add series. Series already on the chart.":

    m_pChart->addSeries(m_pSplineSeries);

    Why do you add same series again? Just append new values to the series...


Log in to reply