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

How to acclerate QLineSeries after using opengl



  • I have to draw a chart with 4 lines. Each line has 6,500 points.

    I've already used setUseOpenGL(true) on thoes lines

    It still needs 5 or 6 seconds to draw these lines.

    How can I accelerate the process?



  • i've tried sth like this:

        QLineSeries *lines2 = new QLineSeries();
        QLineSeries *lines3 = new QLineSeries();
        QLineSeries *lines4 = new QLineSeries();
    
        lines2->setUseOpenGL(true);
        lines3->setUseOpenGL(true);
        lines4->setUseOpenGL(true);
    
    
    
    
        //readData
    
        int nLen = 6500;
        short *sData_CH0 = new short[nLen];
        short *sData_CH1 = new short[nLen];
        short *sData_CH2 = new short[nLen];
        short *sData_CH3 = new short[nLen];
        memset(sData_CH0, 0, sizeof(short)*nLen);
        memset(sData_CH1, 0, sizeof(short)*nLen);
        memset(sData_CH2, 0, sizeof(short)*nLen);
        memset(sData_CH3, 0, sizeof(short)*nLen);
    
        static const int nLen_Header = 160;
        FILE *fp;
        _wfopen_s(&fp,L"d:/11.ocean", L"rb");
    
        double dLen_Binshot = 2 * 4 * nLen;
    
        __int64 nSeekL = nLen_Header + dLen_Binshot * 0;
    
        _fseeki64(fp, nSeekL, SEEK_SET);
    
        int maxY = 0;
        int minY = 0;
        fread(sData_CH0, sizeof(short), nLen, fp);
        fread(sData_CH1, sizeof(short), nLen, fp);
        fread(sData_CH2, sizeof(short), nLen, fp);
        fread(sData_CH3, sizeof(short), nLen, fp);
        fclose(fp);
    
        for (int i=0;i < nLen;i++) {
            if(sData_CH1[i]<(-2000)){
                sData_CH1[i]=0;
            }
            if(sData_CH1[i]<(-2000)){
                sData_CH1[i]=0;
            }
            if(sData_CH1[i]<minY){
                minY= sData_CH1[i];
            }
            if(sData_CH1[i]>maxY){
                maxY= sData_CH1[i];
            }
           lines2->append(QPointF(i, sData_CH1[i]));
        }
        for (int i=0;i < nLen;i++) {
            if(sData_CH2[i]<(-2000)){
                sData_CH2[i]=0;
            }
            if(sData_CH2[i]<(-2000)){
                sData_CH2[i]=0;
            }
            if(sData_CH2[i]<minY){
                minY= sData_CH2[i];
            }
            if(sData_CH2[i]>maxY){
                maxY= sData_CH2[i];
            }
            lines3->append(QPointF(i, sData_CH2[i]));
        }
        for (int i=0;i < nLen;i++) {
            if(sData_CH3[i]<(-2000)){
                sData_CH3[i]=0;
            }
            if(sData_CH3[i]<(-2000)){
                sData_CH3[i]=0;
            }
            if(sData_CH3[i]<minY){
                minY= sData_CH3[i];
            }
            if(sData_CH3[i]>maxY){
                maxY= sData_CH3[i];
            }
            lines4->append(QPointF(i, sData_CH3[i]));
        }
    
    
    
    
        QChart *chart = new QChart();
        chart->addSeries(lines3);
        chart->addSeries(lines4);
        chart->addSeries(lines2);
        chart->createDefaultAxes();
        chart->axisX()->setRange(0, 6500);
        chart->axisY()->setRange(minY, maxY);
        chart->setTitle("chart");
        chartView = new ChartView(chart);
        chartView->setRenderHint(QPainter::Antialiasing);
    
        ui->mainChartLayout->addWidget(chartView);
    

    and it is very fast.

    but when i append the points to lines after adding the lines to the chart, it took 6 second to draw the lines.

    here is the code:

       QLineSeries *lines2 = new QLineSeries();
        QLineSeries *lines3 = new QLineSeries();
        QLineSeries *lines4 = new QLineSeries();
        lines2->setUseOpenGL(true);
        lines3->setUseOpenGL(true);
        lines4->setUseOpenGL(true);
    
        QChart *chart = new QChart();
        chart->addSeries(lines3);
        chart->addSeries(lines4);
        chart->addSeries(lines2);
        chart->createDefaultAxes();
        chart->axisX()->setRange(0, 6500);
        chart->axisY()->setRange(-200, 20000);
        chart->setTitle("chart");
        chartView = new ChartView(chart);
        chartView->setRenderHint(QPainter::Antialiasing);
    
        ui->mainChartLayout->addWidget(chartView);
    
    
    
        int nLen = 6500;
        short *sData_CH0 = new short[nLen];
        short *sData_CH1 = new short[nLen];
        short *sData_CH2 = new short[nLen];
        short *sData_CH3 = new short[nLen];
        memset(sData_CH0, 0, sizeof(short)*nLen);
        memset(sData_CH1, 0, sizeof(short)*nLen);
        memset(sData_CH2, 0, sizeof(short)*nLen);
        memset(sData_CH3, 0, sizeof(short)*nLen);
    
        static const int nLen_Header = 160;
        FILE *fp;
        _wfopen_s(&fp,L"d:/11.ocean", L"rb");
    
        double dLen_Binshot = 2 * 4 * nLen;
    
        __int64 nSeekL = nLen_Header + dLen_Binshot * 0;
    
        _fseeki64(fp, nSeekL, SEEK_SET);
    
        int maxY = 0;
        int minY = 0;
        fread(sData_CH0, sizeof(short), nLen, fp);
        fread(sData_CH1, sizeof(short), nLen, fp);
        fread(sData_CH2, sizeof(short), nLen, fp);
        fread(sData_CH3, sizeof(short), nLen, fp);
        fclose(fp);
    
        for (int i=0;i < nLen;i++) {
            if(sData_CH1[i]<(-2000)){
                sData_CH1[i]=0;
            }
            if(sData_CH1[i]<(-2000)){
                sData_CH1[i]=0;
            }
            if(sData_CH1[i]<minY){
                minY= sData_CH1[i];
            }
            if(sData_CH1[i]>maxY){
                maxY= sData_CH1[i];
            }
           lines2->append(QPointF(i, sData_CH1[i]));
        }
        for (int i=0;i < nLen;i++) {
            if(sData_CH2[i]<(-2000)){
                sData_CH2[i]=0;
            }
            if(sData_CH2[i]<(-2000)){
                sData_CH2[i]=0;
            }
            if(sData_CH2[i]<minY){
                minY= sData_CH2[i];
            }
            if(sData_CH2[i]>maxY){
                maxY= sData_CH2[i];
            }
            lines3->append(QPointF(i, sData_CH2[i]));
        }
        for (int i=0;i < nLen;i++) {
            if(sData_CH3[i]<(-2000)){
                sData_CH3[i]=0;
            }
            if(sData_CH3[i]<(-2000)){
                sData_CH3[i]=0;
            }
            if(sData_CH3[i]<minY){
                minY= sData_CH3[i];
            }
            if(sData_CH3[i]>maxY){
                maxY= sData_CH3[i];
            }
            lines4->append(QPointF(i, sData_CH3[i]));
        }
    
    
    
    
    

Log in to reply