Add new QLineSeries to existing chart



  • This is my function:

    /********************* populate the graph ***********************/
    void MainWindow::graphSelected(QStringList _graphingData, QString sensorName) {
       
        QList<QStringList> list;
        int x = 0;
        foreach (const QString &s, _graphingData) {
            const QStringList parts = s.split(",");
            list.append(parts);
            Q_ASSERT(parts.size() >= 3);
            double y = parts.at(2).toDouble();
            x+=1;
            series->append(x,y);
            if  (Debug){
                qDebug() << x << y;
            }
        }    
    
        series->setName(sensorName);
        chart->addSeries(series);
        chart->setAnimationOptions(QChart::SeriesAnimations);
        chart->createDefaultAxes();
        chart->legend()->setAlignment(Qt::AlignBottom);
        chartView->setRenderHint(QPainter::Antialiasing);
    
        QWidget *chartWindow = new QWidget;
        QVBoxLayout *layout = new QVBoxLayout(chartWindow);
    
        chartWindow->resize(480,320);
        chartWindow->grabGesture(Qt::PanGesture);
        chartWindow->grabGesture(Qt::PinchGesture);
        layout->addWidget(chartView);
        chartWindow->setLayout(layout);
        layout->activate();
        chartWindow->show();
    
        if (Debug){
            qDebug()<<"showed chartwindow";
    
        }
    }
    

    that takes some data that is extracted in a different function and charts it on a QWidget. I've been struggling with how to then select a new set of data for comparison, and EITHER put the new data set (QLinesSeries) on the same chart OR put it on a new chart above the previous one in the QVBoxLayout on the same QWidget.

    What happens now is the new data is put in a new Widget (the old one goes blank and stays in the background. I've looked for ways to try and make the function aware that there is already a QWidget, or QVBoxLayout, etc, but I haven't been able to figure anything out!

    As always, I'm happy to do the legwork if someone can point me in the right direction!!

    Oh - in case it matters, 'chart' is from a class that extends QChart, and 'chartView' from a class that extends QChartView - giving zoom and pan functionality.

    Best regards,
    Scott



  • Sorry to bump this, but it seems like it should be easy to add a series to an existing graph. If it's something obvious, I haven't figured it out in a week of searching and experimenting. Also, I'm having a problem with a QDialog - I'll start a new question...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.