Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Add new QLineSeries to existing chart
Qt 6.11 is out! See what's new in the release blog

Add new QLineSeries to existing chart

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 734 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MScottM
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MScottM
      wrote on last edited by
      #2

      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...

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved