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. why extra lines appear here by QCharts

why extra lines appear here by QCharts

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 1.3k Views 1 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.
  • M Offline
    M Offline
    mr.five
    wrote on last edited by
    #1

    hello,i have used the QChats to draw one line,but when i finish,there are some extra line appeared,could you tell me why these lines here ,thank you so much

    void createCharts()
    {
        QChart *fenshiChart = new QChart();
        fenshiChart->setBackgroundBrush(QBrush(Qt::black));
        fenshiChart->legend()->setVisible(false);
        fenshiChart->setMargins(QMargins(0,0,0,0));
        fenshiChart->layout()->setContentsMargins(0,0,0,0);
        fenshiChart->setBackgroundRoundness(0);
    
        ui->fenshiLineChart->setChart(fenshiChart);
        ui->fenshiLineChart->setRenderHint(QPainter::Antialiasing);
        ui->fenshiLineChart->setContentsMargins(QMargins(0,0,0,0));
    
        QLineSeries *series0 = new QLineSeries();
    
        QPen pen;
        pen.setStyle(Qt::SolidLine);
        pen.setWidth(1);
        pen.setColor(Qt::white);
        series0->setPen(pen);
        fenshiChart->addSeries(series0);
    
        pen.setWidth(1);
        pen.setColor(QColor(176,0,0));
        QValueAxis *axisX = new QValueAxis;
        axisX->setLabelsVisible(false);
        axisX->setRange(1,240);
        axisX->setTickCount(5);
        axisX->setLinePen(pen);
        axisX->setGridLinePen(pen);
        axisX->setMinorTickCount(1);
        axisX->setShadesVisible(false);
        QValueAxis *axisY = new QValueAxis;
        axisY->setTickCount(27);
        axisY->setLinePen(pen);
        axisY->setGridLinePen(pen);
        axisY->setLabelsColor(Qt::white);
        axisY->setLabelFormat("%.2f");
        pen.setStyle(Qt::DotLine);
        axisX->setMinorGridLinePen(pen);
    
        fenshiChart->addAxis(axisX,Qt::AlignBottom);
        fenshiChart->addAxis(axisY,Qt::AlignLeft);
        series0->attachAxis(axisX);
        series0->attachAxis(axisY);
    }
    
    void addData()
    {
        //data
        int itemNumInt = itemNum;
        QLineSeries *series0 = (QLineSeries *)ui->fenshiLineChart->chart()->series().at(0);
        series0->clear();
        qreal index = 0;
        for (int i=0;i<itemNumInt;i++)
        {
            if((time[i]>=93000 && time[i]<113000) || (time[i]>130000 && time[i]<=150000))
            {
                index += 1;
                points.append(QPointF(index,QString::asprintf("%.2f",hstTodayClose[index-1]/100.00).toDouble()));
            }
        }
        series0->append(points);
    }
    

    1f74a6bb-8a2e-4096-9c53-efdbdf0b53a1-image.png
    4ddbe16e-21ed-4613-94c8-30b2541b468a-image.png
    141f9e27-552c-4fe6-904d-941e243bd4a9-image.png

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      there could be junk data in the input. Add them one after another and you may be able to find out which ones are junk.

      M 1 Reply Last reply
      1
      • JoeCFDJ JoeCFD

        there could be junk data in the input. Add them one after another and you may be able to find out which ones are junk.

        M Offline
        M Offline
        mr.five
        wrote on last edited by
        #3

        @JoeCFD thank you ,i have checked ,all points data are normal ,there is no junk

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mchinand
          wrote on last edited by
          #4

          What if you exclude the number->QString formatting->number step when you are appending your points. Do you still get these artifacts?

          M 1 Reply Last reply
          0
          • M mchinand

            What if you exclude the number->QString formatting->number step when you are appending your points. Do you still get these artifacts?

            M Offline
            M Offline
            mr.five
            wrote on last edited by
            #5

            @mchinand thank you ,i know that is not a good method to do so , but i need the required precision ,so have any other better method to take place? in the other hand, i have exclude that ,but there is still have the extra line on the graph , alas~~~

            M JonBJ 2 Replies Last reply
            0
            • M mr.five

              @mchinand thank you ,i know that is not a good method to do so , but i need the required precision ,so have any other better method to take place? in the other hand, i have exclude that ,but there is still have the extra line on the graph , alas~~~

              M Offline
              M Offline
              mchinand
              wrote on last edited by
              #6

              I think the preferred way to do that formatting (format to two decimal places) is:

              QString::number(hstTodayClose[index-1]/100.00, 'f', 2).toDouble();

              There's nothing weird with your indexing of time[] with i and hstTodayClose[] with index? This depends on how those arrays are populated, so could be correct.

              M 1 Reply Last reply
              0
              • M Offline
                M Offline
                mchinand
                wrote on last edited by
                #7

                Also, where is points defined and initialized? Perhaps try clearing that at the start of addData()

                1 Reply Last reply
                1
                • M mchinand

                  I think the preferred way to do that formatting (format to two decimal places) is:

                  QString::number(hstTodayClose[index-1]/100.00, 'f', 2).toDouble();

                  There's nothing weird with your indexing of time[] with i and hstTodayClose[] with index? This depends on how those arrays are populated, so could be correct.

                  M Offline
                  M Offline
                  mr.five
                  wrote on last edited by
                  #8

                  @mchinand ```
                  QString::number(hstTodayClose[index-1]/100.00, 'f', 2).toDouble();

                  this method i have used, but  it  loss precision when i debug out the number.    the points was initialized like this:```
                  QList<QPointF> points={};
                  

                  and i tried to add points.clear() ,but it seems like have no help on the grap ,the extra lines are still there.

                  1 Reply Last reply
                  0
                  • M mr.five

                    @mchinand thank you ,i know that is not a good method to do so , but i need the required precision ,so have any other better method to take place? in the other hand, i have exclude that ,but there is still have the extra line on the graph , alas~~~

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @mr-five

                    • Check @mchinand's comment: if points is not empty (left over from before?) you would "jump back" to x == 0, could make it look screwy.
                    • Verify how it looks using just all points as QPointF(index, index) instead. Should be diagonal line. Any artefacts?
                    • Verify the length of hstTodayClose, is [index-1] always within bounds?
                    • Binary chop the number of points you plot, do the artefacts still appear? Keep chopping in half.
                    • To pass a floating point number of 2 decimal places you shouldn't need to convert to a string and then back to a number. Something like int(num * 100 + 0.5) / 100.0 should work.
                    M 1 Reply Last reply
                    1
                    • JonBJ JonB

                      @mr-five

                      • Check @mchinand's comment: if points is not empty (left over from before?) you would "jump back" to x == 0, could make it look screwy.
                      • Verify how it looks using just all points as QPointF(index, index) instead. Should be diagonal line. Any artefacts?
                      • Verify the length of hstTodayClose, is [index-1] always within bounds?
                      • Binary chop the number of points you plot, do the artefacts still appear? Keep chopping in half.
                      • To pass a floating point number of 2 decimal places you shouldn't need to convert to a string and then back to a number. Something like int(num * 100 + 0.5) / 100.0 should work.
                      M Offline
                      M Offline
                      mr.five
                      wrote on last edited by
                      #10

                      @JonB thank you.

                      1. the points is empty when i used points.clear() before add data, but it is not works
                        2.it is not diagonal line, like this ,and i do not know why?
                        dcf61569-20b4-4d73-8a82-42b0e5a8761a-image.png ![alt text](image url)
                        1c7234e4-74b3-4ed7-90cc-efef1d206239-image.png
                      JonBJ 1 Reply Last reply
                      0
                      • M mr.five

                        @JonB thank you.

                        1. the points is empty when i used points.clear() before add data, but it is not works
                          2.it is not diagonal line, like this ,and i do not know why?
                          dcf61569-20b4-4d73-8a82-42b0e5a8761a-image.png ![alt text](image url)
                          1c7234e4-74b3-4ed7-90cc-efef1d206239-image.png
                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #11

                        @mr-five
                        Looks like two separate diagonal lines. Does your x value change from positive to negative?? What is the range of your index variable? Make it int index instead of qreal, any difference? Only print the first 50% of all the points, do you then get just the left-hand line?

                        M 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @mr-five
                          Looks like two separate diagonal lines. Does your x value change from positive to negative?? What is the range of your index variable? Make it int index instead of qreal, any difference? Only print the first 50% of all the points, do you then get just the left-hand line?

                          M Offline
                          M Offline
                          mr.five
                          wrote on last edited by mr.five
                          #12

                          @JonB
                          e387ec4d-4ae8-4c79-9890-5150510b8014-image.png
                          f63cadb8-77b8-4e76-8441-1bb04f3233e2-image.png

                          i found one probable cause is that i forgot to initialize the range of the Y axis, and after i do so:

                          ui->fenshiLineChart->chart()->axes(Qt::Vertical).at(0)->setRange(todayLow[itemNum-1],todayHigh[itemNum-1]);
                          

                          the graph only leave one extra line like this,and i do not know the reason again,thank you

                          JonBJ 1 Reply Last reply
                          0
                          • M mr.five

                            @JonB
                            e387ec4d-4ae8-4c79-9890-5150510b8014-image.png
                            f63cadb8-77b8-4e76-8441-1bb04f3233e2-image.png

                            i found one probable cause is that i forgot to initialize the range of the Y axis, and after i do so:

                            ui->fenshiLineChart->chart()->axes(Qt::Vertical).at(0)->setRange(todayLow[itemNum-1],todayHigh[itemNum-1]);
                            

                            the graph only leave one extra line like this,and i do not know the reason again,thank you

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #13

                            @mr-five
                            It looks like that would be produced if you somehow have an extra (0, 0) at the end of the series?

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mr.five
                              wrote on last edited by
                              #14

                              @JonB @JoeCFD @mchinand thank you all! i have found the reason,the axis count not suit my series count,if some missed ,there will have extra lines

                              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