I have a vector with date and with values. The problem is that the graph does not correctly display time on the x-axis. For example, if the time is 17:27:... the chart displays 05:49:... and because of this it is plotted incorrectly!
#include "qcustomplot.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QCustomPlot* plot = new QCustomPlot();
setCentralWidget(plot);
plot->xAxis->setLabel("Time");
plot->yAxis->setLabel("Position");
QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime);
dateTicker->setDateTimeFormat("HH:mm:ss.zzz");
plot->xAxis->setTicker(dateTicker);
QVector<double> xData, yData;
QVector<QString> dateTime = {"2023-08-15 17:27:02.994591",
"2023-08-15 17:27:16.240445",
"2023-08-15 17:27:16.441496",
"2023-08-15 17:27:16.639997",
"2023-08-15 17:27:16.841136",
"2023-08-15 17:27:17.424592",
"2023-08-15 17:27:17.240649",
"2023-08-15 17:27:17.441818",
"2023-08-15 17:27:17.640868",
"2023-08-15 17:27:17.841120",
};
for (const QString& value : dateTime)
{
QStringList values = value.split(" ");
QDateTime dataTime = QDateTime::fromString(values[1].chopped(3), "HH:mm:ss.zzz");
xData.append(dataTime.toMSecsSinceEpoch());
}
for (int i = 0; i < dateTime.size(); ++i)
{
yData.append(i + 1);
}
QCPGraph* graph = plot->addGraph();
graph->setData(xData, yData);
plot->setInteractions(QCP::iRangeZoom | QCP::iRangeDrag);
plot->rescaleAxes();
plot->replot();
}
Aucun commentaire:
Enregistrer un commentaire