QChart's x-axis, time axis time conversion

Before conversion:

 It can be clearly seen that the X time axis format is not converted to the time axis and displayed, but the double type!

 

 Then we convert it to QDateTime type!

By the way, we made the time red to make it easier to see, the effect is as shown in the picture!

Rubber 2022-12-19 14-50-58

Not much to say, just look at the code!

 const QPoint curPos = event->pos();


        QPointF curVal = chart->mapToValue(QPointF(curPos));
        const double yCentral = curVal.y();
        QDateTime  xCentral = QDateTime::fromMSecsSinceEpoch(curVal.x());
        QString result = "";
        result = QDateTime::fromMSecsSinceEpoch(xCentral.toMSecsSinceEpoch()).toString(Qt::ISODate);
       // QString coordStr = QString("X = %1, Y = %2").arg(result).arg(yCentral);
        QString coordStr = QString("Y = %1, X = ").arg(yCentral);
        QString cl = "-";
        m_coordItem->setText(coordStr);
        ui->label_2->setText(result);
        QPoint offset = curPos - m_lastPoint;
        m_lastPoint = curPos;

        if (!m_alreadySaveRange)
        {
            this->saveAxisRange();
            m_alreadySaveRange = true;
        }
        chart->scroll(-offset.x(), offset.y());

Guess you like

Origin blog.csdn.net/qq_55365635/article/details/128372563