lundi 23 juillet 2018

Alloting fix co-ordinates(x,y) for Qt Simple line chart

I am creating a simple line chart graph in QT 5.7.

Following is my certificate_page_childs table structure:

enter image description here

My c++ code :

QLineSeries *series = new QLineSeries();
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
QString db_path = QDir::currentPath();
db_path =  db_path + QString("/some_file");
db.setDatabaseName(db_path);
db.open();
QSqlQuery query;
 query.prepare("SELECT hardness_val FROM certificate_page_childs where cp_id=:value");
 query.bindValue(0,statisticalanalysis::cert_id_gbl);
 if(query.exec()){
      int d = 1;
      while (query.next()) {
          series->append(d, query.value(0).toDouble()); //Method 1
          //qDebug() << query.value(0).toString();
          //*series << QPointF(d,query.value(0).toDouble()); // Method 2
          qDebug() << d;
          d++;

      }
 }
 else
 {
     qDebug() << query.lastError();
 }
 db.close();
 QChart *chart = new QChart();
 chart->legend()->hide();
 chart->addSeries(series);
 chart->createDefaultAxes();
 chart->setTitle("Simple line chart example");
 chart->setAnimationOptions(QChart::SeriesAnimations);
 ui->graphicsView->setRenderHint(QPainter::Antialiasing);
 ui->graphicsView->setChart(chart);

Following is my output :

Needed output

What i need :

enter image description here

X axis : No of readings

Y axis : Some value per reading

Can anyone guide me till desired results are achieved ?

Aucun commentaire:

Enregistrer un commentaire