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

Array of QLineSeries



  • How can i put my series into an array?

    series->setColor(Qt::blue);
    series->setName(sr);
    series1->setName(sr1);
    series1->setColor(Qt::green);
    series2->setName(sr2);
    series2->setColor(Qt::yellow);
    series3->setName(sr3);
    series3->setColor(Qt::darkBlue);
    series4->setName(sr4);
    series4->setColor(Qt::cyan);
    series5->setName(sr5);
    series5->setColor(Qt::black);
    series6->setName(sr6);
    series6->setColor(Qt::gray);
    series7->setName(sr7);
    series7->setColor(Qt::red);
    
    
    chart->addSeries(series);
    chart->addSeries(series1);
    chart->addSeries(series2);
    chart->addSeries(series3);
    chart->addSeries(series4);
    chart->addSeries(series5);
    chart->addSeries(series6);
    chart->addSeries(series7);
    chart->legend()->setVisible(true);
    //chart->setTheme(QChart::ChartThemeBlueIcy);
    chart->setAnimationOptions(QChart::AllAnimations);
    
    axisX->setTickCount(5);
    axisX->setRange(0, +2);
    chart->addAxis(axisX, Qt::AlignBottom);
    series->attachAxis(axisX);
    series1->attachAxis(axisX);
    series2->attachAxis(axisX);
    series3->attachAxis(axisX);
    series4->attachAxis(axisX);
    series5->attachAxis(axisX);
    series6->attachAxis(axisX);
    series7->attachAxis(axisX);
    
    
    axisY->setTickCount(5);
    axisY->setRange(0,2);
    chart->addAxis(axisY, Qt::AlignLeft);
    series->attachAxis(axisY);
    series1->attachAxis(axisY);
    series2->attachAxis(axisY);
    series3->attachAxis(axisY);
    series4->attachAxis(axisY);
    series5->attachAxis(axisY);
    series6->attachAxis(axisY);
    series7->attachAxis(axisY);
    
    
    chartView->setRenderHint(QPainter::Antialiasing);
    ui->gridLayout->addWidget(chartView);
    

    I've tried to add

    QLineSeries *series[7];
    

    on my header. And after that, i wrote a for loop to cpp

    for(int i=0; i<8; i++)
    {
    //do something with series[i]
    }
    

    but it says me series[1] doesnt declare in this scope


  • Lifetime Qt Champion

    @suslucoder said in Array of QLineSeries:

    I've tried to add

    Where?

    "but it says me series[1] doesnt declare in this scope" - again: where did you declare the array?



  • @jsulm in

    void VeriGoster::Timer_Slot()
    {
        static float q_x=0;
        auto Timer = [=] (QQueue<double> &queue, QLineSeries &series)->void
        {
            if(!queue.isEmpty())
                  {
                     double num=queue.dequeue();
                     q_x += 0.1;
                     series.append(q_x, num);
                     chart->update();
                     chart->scroll(6,0);
                     qDebug() << q_x << num;
                   }
        };
    
         Timer(queue, *series);
         Timer(queue1,*series1 );
         Timer(queue2, *series2);
         Timer(queue3, *series3);
         Timer(queue4, *series4);
         Timer(queue5, *series5);
    


  • @suslucoder
    And where does the code you show generate

    but it says me series[1] doesnt declare in this scope

    ?

    Where is the for loop you say you are trying?

    Also, where does it use the

    QLineSeries *series[7];
    

    you say you are having trouble with? I do not see it using any array of anything, which is what your whole question is about...


Log in to reply