QCustomPlot Discussion and Comments

Timeticker questionReturn to overview

Hello,
in my setuplogplot I have thiscode:

  QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime);
        timeTicker->setTimeFormat("%hh:%mm:%ss"); 
        m_ui->logplot->xAxis->setTicker(timeTicker);     

I read the time from a list with this command:

 x.append(QTime::fromString(fields.at(0),"hh:mm:ss").msecsSinceStartOfDay()/10000.0);//time

a qDebug shows what it is doing:
Zeile1588 line= "12:06:16"
Zeile1580 Zeit x= QVector(4225.9, 4226, 4226, 4226, 4226.1, 4226.1, 4226.2,

but then I get an error:
void QCPGraph::addData(const QVector<double>&, const QVector<double>&, bool) keys and values have different sizes: 3515 0

after this error my graph has a xAxis like that:
0 - 01H:08m:30s - - - 01h:09m:00s - - - 01h:09m:30s
if I uncommand the timeTicker
// m_ui->logplot->xAxis->setTicker(timeTicker);
i get the XAxis like in the QVector
4225.9, 4226, 4226, 4226, 4226.1, 4226.1, 4226.2
what am I doing wrong?
I want the time as it is 12h:06m:16s

Show your addData call. You provide a y vector that is too small. It has no entries, but your x vector has 3515 entries. Of course, data must have both x and y, and that's why you get the warning from QCustomPlot.

Hi Isso,
That can`t be the fault. I have 55 y vektors.
At every time the x vector gets a time item, all the 55 y vectors get an item too.
And what do i have to write that my xvector ticker writes the time what it has read in?

                                  x.append(QTime::fromString(fields.at(0),"hh:mm:ss").msecsSinceStartOfDay()/10000.0);//time

                                  // take first value and stored into x
                                     m_ui->logfilewidget->setItem(l, 0,new QTableWidgetItem(fields.at(0)));

                                    qDebug()<<"Zeile1588 line="<<fields.at(0);
                                   qDebug()<<"Zeile1580 Zeit x="<<x;
                                  y1.append(fields.at(1).toDouble()); // rpm
                                   m_ui->logfilewidget->setItem(l,1, new QTableWidgetItem(fields.at(1)));
                                  y55.append(fields.at(1).toDouble());//rpm<1500
                                  //     double t=(fields.at(2).toDouble());//
                                  //     double u=(t-32)*55556/100000;// calculate celsius from fahrenheit
                                  y2.append(fields.at(2).toDouble());//coolant temp
                                   m_ui->logfilewidget->setItem(l,2, new QTableWidgetItem(fields.at(2)));
                                 qDebug() << "Zeile1563:"<<y2;

Hi Leopold,

whatever you're doing, the output of addData is pretty definitive: the vectors you're passing to it have different sizes, and they should have the same. In the code you've posted I don't see an addData call, so I can't tell you what's wrong exactly. (On a side note: what worries me is that you have variables that indicate you're hardcoding indices of vector objects in the name. If you truly have 55 or more vectors, rather use a list of vectors, for example.)

Regarding the time conversion: What is the reason you divide your values by 10000? The time coordinate of QCustomPlot is seconds (as floating point value).

Hi DerManu,
in that thread "read time from file" ian suggested to divide values by 10000.

What do you mean with list of vevectors?In the setup i define about 60 y vectors, then I read from different lists with 30 to 55 fields.
And yes even i have append commands the debug says error in addData!

supposed to be 1000. converting from MS to seconds

Hi Ian,
you are right. I just tried different divisors and when I divided by 1000.0 everything was like i wanted.
Thank you

You should definitely switch to a more flexible approach with those vectors. Like I said, consider QList<QVector<double> >, and not manually counting up variable names. That leads to issues like you are observing, that you forget to append the proper data amount to one of those vectors and then call QCPGraph::addData with two differently sized vectors.

Hi,
give me a hint where those "QCPGraph::addData with two differently sized vectors." vectors are.
"that you forget to append the proper data amount to one of those vectors "
Do you think, i should fill up the unused vectors with zeros?

     QString line = in.readLine();
                          while(!in.atEnd())
                          {
                              int l=line_count;
                              m_ui->logfilewidget->insertRow(l);
                              line = in.readLine();// read first line and so on

                              qDebug() <<"2112"<< line;
                              qDebug() << "Zeile2138:"<<line_count;
                              QStringList fields = line.split(',');
                               qDebug() <<"2115"<< line;
                              for (int i = 0; i < r; ++i)
                                  {
                                       m_ui->logfilewidget->setItem(l-1, i,new QTableWidgetItem(fields.at(i)));
                                  }
                              x.append(tick);
                              tick++;
                                m_ui->logfilewidget->setItem(l, 0,new QTableWidgetItem(fields.at(0)));
                               y1.append(fields.at(1).toDouble()); // rpm
                                 m_ui->logfilewidget->setItem(l,1,new QTableWidgetItem(fields.at(1)));
                               y55.append(fields.at(1).toDouble());//rpm<1500
                               //  m_ui->logfilewidget->setItem(l, 0,new QTableWidgetItem(fields.at(0)));
                               y17.append(fields.at(2).toDouble());//idle error
                                 m_ui->logfilewidget->setItem(l, 2,new QTableWidgetItem(fields.at(2)));
                               y16.append(fields.at(3).toDouble());//idle Pos steps
                                 m_ui->logfilewidget->setItem(l, 3,new QTableWidgetItem(fields.at(3)));
                               y9.append(fields.at(4).toDouble());// idle switch
                                 m_ui->logfilewidget->setItem(l, 4,new QTableWidgetItem(fields.at(4)));
                               y2.append(fields.at(5).toDouble());//water temp
                                 m_ui->logfilewidget->setItem(l, 5,new QTableWidgetItem(fields.at(5)));
                               y6.append(fields.at(6).toDouble());//Map
                                 m_ui->logfilewidget->setItem(l, 6,new QTableWidgetItem(fields.at(6)));
                               y19.append(fields.at(7).toDouble());//Ignadv
                                 m_ui->logfilewidget->setItem(l, 7,new QTableWidgetItem(fields.at(7)));
                               y4.append(fields.at(8).toDouble());//inlet air
                                 m_ui->logfilewidget->setItem(l,8,new QTableWidgetItem(fields.at(8)));
                               y8.append(fields.at(9).toDouble());//Throttle volt
                                 m_ui->logfilewidget->setItem(l, 9,new QTableWidgetItem(fields.at(9)));
                               y7.append(fields.at(10).toDouble());//Battery
                                 m_ui->logfilewidget->setItem(l, 10,new QTableWidgetItem(fields.at(10)));
                               y20.append(fields.at(11).toDouble()); //coil time
                                 m_ui->logfilewidget->setItem(l,11,new QTableWidgetItem(fields.at(11)));
                               y33.append(fields.at(12).toDouble()); // closed loop
                                 m_ui->logfilewidget->setItem(l, 12,new QTableWidgetItem(fields.at(12)));
                               y29.append(fields.at(13).toDouble());//lambda volt
                                 m_ui->logfilewidget->setItem(l,13,new QTableWidgetItem(fields.at(13)));
                               y35.append(fields.at(14).toDouble());//fuel trim
                                 m_ui->logfilewidget->setItem(l, 14,new QTableWidgetItem(fields.at(14)));
                               y38.append(fields.at(15).toDouble());// idle base
                                 m_ui->logfilewidget->setItem(l,15,new QTableWidgetItem(fields.at(15)));
                               y28.append(fields.at(17).toDouble());//F1
                                 m_ui->logfilewidget->setItem(l, 17,new QTableWidgetItem(fields.at(17)));
                              // y38.append(fields.at(18).toDouble());//F2
                                   m_ui->logfilewidget->setItem(l, 16,new QTableWidgetItem(fields.at(16)));
                              //   y19.append(fields.at(19).toDouble());//Byte1
                                     m_ui->logfilewidget->setItem(l,18,new QTableWidgetItem(fields.at(18)));
                                      m_ui->logfilewidget->setItem(l,19,new QTableWidgetItem(fields.at(19)));
                               y45.append(fields.at(20).toDouble());//Byte 2
                                 m_ui->logfilewidget->setItem(l, 20,new QTableWidgetItem(fields.at(20)));
                               y54.append(fields.at(21).toDouble()); // rpm raw
                                 m_ui->logfilewidget->setItem(l, 21,new QTableWidgetItem(fields.at(21)));
                               y56.append(fields.at(22).toDouble()); // unknown load?
                                 m_ui->logfilewidget->setItem(l,22,new QTableWidgetItem(fields.at(22)));
                               y57.append(fields.at(23).toDouble());// ign_tune
                                 m_ui->logfilewidget->setItem(l, 23,new QTableWidgetItem(fields.at(23)));
                               y58.append(fields.at(24).toDouble());// idlerpm_tune
                                 m_ui->logfilewidget->setItem(l, 24,new QTableWidgetItem(fields.at(24)));
                               y59.append(fields.at(25).toDouble());//fuel_tune
                                 m_ui->logfilewidget->setItem(l,25,new QTableWidgetItem(fields.at(25)));
                              //	 y26.append(fields.at(26).toDouble());//Virtual Maf
                                   m_ui->logfilewidget->setItem(l,26,new QTableWidgetItem(fields.at(26)));
                              //   y27.append(fields.at(27).toDouble());// Virtual fuel l/s
                                     m_ui->logfilewidget->setItem(l,27,new QTableWidgetItem(fields.at(27)));
                              //	 y28.append(fields.at(28).toDouble());//virtual fuel l/h
                                       m_ui->logfilewidget->setItem(l,28,new QTableWidgetItem(fields.at(28)));
                              //   y29.append(fields.at(29).toDouble());//speed
                                         m_ui->logfilewidget->setItem(l, 29,new QTableWidgetItem(fields.at(29)));
                              //	 y30.append(fields.at(30).toDouble());// Gps long
                                           m_ui->logfilewidget->setItem(l, 30,new QTableWidgetItem(fields.at(30)));
                              //	 y31.append(fields.at(31).toDouble()); // gps lat
                                             m_ui->logfilewidget->setItem(l,31,new QTableWidgetItem(fields.at(31)));
                                             m_ui->logfilewidget->setItem(l,32,new QTableWidgetItem(fields.at(32)));
                              line_count++;

                          }

Apart from that code desperately needing refactoring, I couldn't see any call to a QCustomPlot related method. So no, I don't know where you make the wrong call because you're still not showing that section of your code :)
How about you go into debug mode and set a breakpoint at the according debug message. Then you'll see in the method stack where you're inputting mismatching vectors.

Hi DerManu,
if i search for addData on the whole project, i should find the comand but there isn`t one on this plot.
How to set the breakpoint on the debug message. There is no line where to find the error.
but then I get an error:
1

void QCPGraph::addData(const QVector<double>&, const QVector<double>&, bool) keys and values have different sizes: 3515 0

Well somewhere in your code you pass your vectors to QCustomPlot, right? That's the spot you should find. Maybe you don't use addData but setData instead, or a direct call to the container. You should know your code better than me :)