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. Speed Problem with Qchart and Drawing BarChart in Qt5.7
Forum Updated to NodeBB v4.3 + New Features

Speed Problem with Qchart and Drawing BarChart in Qt5.7

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 3.0k Views 2 Watching
  • 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.
  • H Offline
    H Offline
    hadi_m
    wrote on last edited by hadi_m
    #1

    Hello to All
    I have serious problem with drawing Chart in Qt, I created the following simple project base on Qt Bar chart Sample project, My chart changes over time dynamically. My problem with it is, when I increase the number of bars the program is too slow and it takes a long time to drawing chart. I use a thread but it does not matter at all. So how can I increase the speed of drawing chart?

    #define BinNumber 100
    #define BinLenght   0.002
    unsigned long hist[BinNumber];
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
            QMainWindow window;
            window.show();
            QList<QBarSet*> Bins;
            QBarSeries *series;
            QChart *chart;
            QChartView *chartView;
            float deltaV = BinLenght / float(BinNumber);
            series = new QBarSeries();
            chart = new QChart();
            chart->setVisible(false);
            clock_t chartStart = clock();
            for (int i = 0; i < BinNumber; i++) {
                hist[i] = (int)qrand() % 1000;
                QBarSet * bar = new QBarSet(QString::number((i + 1)*deltaV));
                *bar << hist[i];
                Bins.append(bar);
    
                series->append(bar);
            }
            while (false)
            {
                int i = 0;
                hist[i] = 0;
                QBarSet * bar = new QBarSet(QString::number((i + 1)*deltaV));
                *bar << 0;
                Bins.append(bar);
    
                series->append(bar);
            }
            QValueAxis *axisX = new QValueAxis;
            axisX->setRange(0, 5);
            QValueAxis *axisY = new QValueAxis;
            axisY->setRange(0, 1000);
            chart->addSeries(series);
            chart->setTitle("Histogram Of Input Signal");
            chart->createDefaultAxes();
            chart->setAxisY(axisY, series);
            chartView = new QChartView(chart);
            chartView->setRenderHint(QPainter::Antialiasing);
            window.setCentralWidget(chartView);
            window.resize(420, 300);
            chart->setVisible(true);
            clock_t chartend = clock();
            qDebug()<< "Execution time is :" << (float(chartend - chartStart) /CLOCKS_PER_SEC);
        return a.exec();
    }
    

    I should mention that I measure my code with some powerful profiler and the command “chart->addSeries(series);” take 510 millisecond to execute my forloop take 3039 ms for 100 BinNumber. QChart does any method for fast drawing? How can I edit this code for increasing drawing speed?

    I want to know everything that I don't know, maybe I don't have enough time for learning all of them but I have a chance to try, and it is enough for me ,so I really appropriate if you learn me anything
    Unknown Programmer

    FlotisableF 1 Reply Last reply
    0
    • H hadi_m

      Hello to All
      I have serious problem with drawing Chart in Qt, I created the following simple project base on Qt Bar chart Sample project, My chart changes over time dynamically. My problem with it is, when I increase the number of bars the program is too slow and it takes a long time to drawing chart. I use a thread but it does not matter at all. So how can I increase the speed of drawing chart?

      #define BinNumber 100
      #define BinLenght   0.002
      unsigned long hist[BinNumber];
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
              QMainWindow window;
              window.show();
              QList<QBarSet*> Bins;
              QBarSeries *series;
              QChart *chart;
              QChartView *chartView;
              float deltaV = BinLenght / float(BinNumber);
              series = new QBarSeries();
              chart = new QChart();
              chart->setVisible(false);
              clock_t chartStart = clock();
              for (int i = 0; i < BinNumber; i++) {
                  hist[i] = (int)qrand() % 1000;
                  QBarSet * bar = new QBarSet(QString::number((i + 1)*deltaV));
                  *bar << hist[i];
                  Bins.append(bar);
      
                  series->append(bar);
              }
              while (false)
              {
                  int i = 0;
                  hist[i] = 0;
                  QBarSet * bar = new QBarSet(QString::number((i + 1)*deltaV));
                  *bar << 0;
                  Bins.append(bar);
      
                  series->append(bar);
              }
              QValueAxis *axisX = new QValueAxis;
              axisX->setRange(0, 5);
              QValueAxis *axisY = new QValueAxis;
              axisY->setRange(0, 1000);
              chart->addSeries(series);
              chart->setTitle("Histogram Of Input Signal");
              chart->createDefaultAxes();
              chart->setAxisY(axisY, series);
              chartView = new QChartView(chart);
              chartView->setRenderHint(QPainter::Antialiasing);
              window.setCentralWidget(chartView);
              window.resize(420, 300);
              chart->setVisible(true);
              clock_t chartend = clock();
              qDebug()<< "Execution time is :" << (float(chartend - chartStart) /CLOCKS_PER_SEC);
          return a.exec();
      }
      

      I should mention that I measure my code with some powerful profiler and the command “chart->addSeries(series);” take 510 millisecond to execute my forloop take 3039 ms for 100 BinNumber. QChart does any method for fast drawing? How can I edit this code for increasing drawing speed?

      FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on last edited by
      #2

      @hadi_m
      I think maybe the new statement in the for loop dominate the speed.

      you have already knows how many bars you need, why not use a QList or QVector to allocate the memory first, and then go though it and set the proper information to the elements?

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hadi_m
        wrote on last edited by hadi_m
        #3

        Thanks for your replying
        I tested with local QBarSet Qlist instead of dynamically created it but it doesn’t matter on speed.
        I should mention I test my program by some powerful performance validator tools and I notice the line “chart->addSeries(series);” take too long time and of course my forloop take time when BarNumber Increases to 1000.

        I want to know everything that I don't know, maybe I don't have enough time for learning all of them but I have a chance to try, and it is enough for me ,so I really appropriate if you learn me anything
        Unknown Programmer

        W 1 Reply Last reply
        0
        • H hadi_m

          Thanks for your replying
          I tested with local QBarSet Qlist instead of dynamically created it but it doesn’t matter on speed.
          I should mention I test my program by some powerful performance validator tools and I notice the line “chart->addSeries(series);” take too long time and of course my forloop take time when BarNumber Increases to 1000.

          W Offline
          W Offline
          wanghl
          wrote on last edited by
          #4

          @hadi_m bar set is slow。unfortunately,no way resolve it

          1 Reply Last reply
          0
          • Venkatesh VV Offline
            Venkatesh VV Offline
            Venkatesh V
            wrote on last edited by
            #5

            @hadi_m
            Try by taking different thread for those two loops and addSeries can do it in main thread only.

            jsulmJ 1 Reply Last reply
            2
            • Venkatesh VV Venkatesh V

              @hadi_m
              Try by taking different thread for those two loops and addSeries can do it in main thread only.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Venkatesh-V If chart->addSeries(series); is the problem, then I don't think using multi threading will give any advantage (instead it will complicate stuff).

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

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