QCustomPlot Discussion and Comments

Database, no point displayReturn to overview

HI,
i have a simple Graph that show me values from a Date. i save a QDate in a Qmysql Database as String.
From this data i want to show the Graph but my points do not want to be displayed.

Can someone help me ?

get data from mysql.

 QVector<double> valeur;
    QVector<double> date;
    QDateTime d;
    int pourcentage = 10000;
    button_DB->setEnabled(false);

    QSqlDatabase basededonnee = QSqlDatabase::addDatabase("QMYSQL");   /
    int nb=500;

    basededonnee.setHostName(serveurIP->text());       
    basededonnee.setDatabaseName("Cotracker");        
    basededonnee.setUserName("Cotracker");                  
    basededonnee.setPassword("snir");                            

    if(basededonnee.open())
    {
        QSqlQuery query;                                                                                      
         qDebug() << "Opening of the database.";

         if(query.exec("SELECT capteur2,date  FROM cotracker"))               
         {
             while((query.next()) && (nb > 0))                                                                
             {
                 valeur.append(query.value(0).toDouble() / pourcentage);
                 QDateTime d ;
                 d = QDateTime::fromString(query.value(1).toDateTime(), "dd MM yyyy");                   
                 date.append(d.toTime_t());
                 nb --;
             }
             makePlot(valeur, date);
             basededonnee.close();
             qDebug() << "Data base closure.";
             button_DB->setEnabled(true);
         }
         else
         {
             qDebug() << "Failed to extract data in call a query :" <<basededonnee.lastError();
             qDebug() << "Data base closure.";
             basededonnee.close();
             button_DB->setEnabled(true);
         }
    }
    else
     {
             qDebug() << "Failed to open database :" <<basededonnee.lastError(); 
             listeMessages->append("Failed to open Database.");
              basededonnee.close();
             button_DB->setEnabled(true);
      }

the makeplot

void cotracker::makePlot(QVector<double>& valeur, QVector<double>& date)
{
    QDateTime utc = QDateTime::currentDateTimeUtc();               
    uint now = utc.toTime_t();                                                                 

    customPlot->setInteraction(QCP::iRangeDrag, true);             
    customPlot->axisRect()->setRangeDrag(Qt::Horizontal);         

    customPlot->addGraph();                            

    customPlot->graph(0)->setData(valeur, date);                                

    QCPScatterStyle myScatter;
    myScatter.setShape(QCPScatterStyle::ssCircle);
    myScatter.setPen(QPen(Qt::blue));
    myScatter.setBrush(Qt::white);
    myScatter.setSize(5);
    customPlot->graph(0)->setScatterStyle(myScatter);

    customPlot->xAxis->setLabel("Date");                                               
    customPlot->yAxis->setLabel("Pourcentage");                                
    QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime); 
     customPlot->xAxis->setTicker(dateTicker);

     customPlot->xAxis->setRange(now-24*3600*7, now);                                                   
     dateTicker->setDateTimeFormat("d. MMM\nyyyy");                                                         

     customPlot->yAxis->setRange(0, 1);                                                                             
     customPlot->replot();                                                                                                          
}

thanks !

I think this line is wrong:

customPlot->graph(0)->setData(valeur, date);

I believe, from the way you are setting up your chart, you need to reverse the data:

customPlot->graph(0)->setData(date,valeur);