QChart axisX actualized DateTime
-
Hi,
axisX shows 08:21 18.01.70 only, I would to show actualized DT on axisX. axisY Value type work properly, code:QLineSeries *sData = new QLineSeries(); QDateTime actualDateTime = QDateTime::currentDateTime(); sData->append(actualDateTime.toSecsSinceEpoch(),tepl01.toFloat());//toMsecSinceEpoch() do overflow variable and shows nothing QChart *tempChart = new QChart(); tempChart->addSeries(sData); tempChart->legend()->hide(); tempChart->setTitle("Ser data"); tempChart->createDefaultAxes();//not work without this QDateTimeAxis *axisX = new QDateTimeAxis; //axisX->setTickCount(10); axisX->setFormat("hh:mm dd.MMM.yy"); axisX->setTitleText("Datum"); //tempChart->addAxis(axisX, Qt::AlignBottom);//shows seconds from epoch only, not DateTime format tempChart->setAxisX(axisX, sData); QValueAxis *axisY = new QValueAxis; axisY->setLabelFormat("%.1f"); axisY->setTitleText("Serial data");
// tempChart->addAxis(axisY, Qt::AlignLeft);
tempChart->setAxisY(axisY, sData);QChartView *showChart = new QChartView(tempChart); setCentralWidget(showChart); showChart->setRenderHint(QPainter::Antialiasing);
Is problem overflowing q64 due big toMsecSinceEpoch() or...?
thx -
Hi!
There's a typo in your code, should betoMSecsSinceEpoch
, nottoSecsSinceEpoch
:sData->append(actualDateTime.toSecsSinceEpoch(),tepl01.toFloat());
Have a look at the DateTimeAxis Example.
-
Hi,
code above is in periodically called method void MainWindow::serialData() in file mainwindow.cpp I researched that mentioned problem is probably caused by leaving this method and code entering to main method to show window. Object QChartView maybe corrupted or destructed. Creating window object and show it: MainWindow w;
w.show(); from this method not work.
How to show main window from this method or how to solve this situation? -
I had similar problem with toMSecssinceEpoch() method. The ChartView does not show plotted points. I changed it to toSecsSinceEpoch() and QDatetimeAxis is shown in ChartView. Thanks.