我目前正在使用qt图表,x轴以第二种格式显示时间,但是我希望它以hh:mm:ss.ms格式显示x轴值。有没有办法改变我的轴,使其以这种格式显示?
我遵循了以下示例:https://doc.qt.io/qt-5.11/qdatetime.html#toMSecsSinceEpoch
但是我的坐标轴当前仅显示0:00,这很奇怪
以下方法通过使用createDefaultAxes()将新值正确地添加到图形中,但是由于某些原因,对于我的其他自定义轴,它不能正确地添加新值。
void RecordWidgetGraph::setBitrate (qint64 bitrate, qint64 duration){
// Appends new values and updates graph
if(bitrate != 0){
double timestampDouble = (double) duration /1000;
double bitrateDouble = (double) bitrate /1000000;
lineSeries->append(timestampDouble, bitrateDouble);
this->chart()->removeSeries(lineSeries);
this->chart()->addSeries(lineSeries);
this->chart()->createDefaultAxes();
QDateTimeAxis *axisX = new QDateTimeAxis;
axisX->setFormat("m:ss");
axisX->setTickCount(10);
this->chart()->addAxis(axisX, Qt::AlignBottom);
lineSeries->attachAxis(axisX);
this->chart()->scroll(chartCounter /5 , 0);
this->chart()->axisX()->setRange(timestampDouble - 10, timestampDouble + 2);
chartCounter++;
}
}
这是当前的样子。第一个轴以秒为单位显示时间,但DateTimeAxis仅显示0:00。
这是我创建图像的setupGraph方法。
QChart* RecordWidgetGraph::setupGraph(){
lineSeries = new QLineSeries();
timeSeries = new QTime();
// Create chart, add data, hide legend, and add axis
Chart * chart = new Chart();
chart->legend()->hide();
chart->addSeries(lineSeries);
chart->createDefaultAxes();
// Customize the title font
QFont font;
font.setPixelSize(3);
chart->setTitleFont(font);
chart->setTitleBrush(QBrush(Qt::black));
// chart->setTitle("Bitrate per second mbps");
// Change the line color and weight
QPen pen(QRgb(0x000000));
pen.setWidth(1);
lineSeries->setPen(pen);
this->setChart(chart);
// this->chart()->axisX()->setTitleText("Seconds");
this->chartCounter = 0;
bitrateTimer.start();
return(chart);
}