我正在尝试实现类似https://doc.qt.io/qt-5.9/qtcharts-datetimeaxis-example.html的目标。
在一个方法中我有这个代码
QDateTime past = QDateTime::currentDateTime().addMonths(-10);
QDateTime now = QDateTime::currentDateTime();
qreal pastvalue = 4;
qreal nowvalue = 4;
axisY = new QValueAxis();
axisX= new QDateTimeAxis();
chart = new QChart();
series = new QLineSeries();
/*Y*/
axisY->setLabelFormat("%i");
axisY->setTitleText("Numero dispositivi");
axisY->setMin(0);
axisY->setMax(5);
/*X*/
axisX->setTickCount(2);
axisX->setMin(past);
axisX->setMax(now);
axisX->setFormat("dd-MM-yyyy h:mm:ss");
/*series/*
series->attachAxis(axisX);
series->attachAxis(axisY);
series->append(past.toSecsSinceEpoch(),pastvalue);
series->append(past.toSecsSinceEpoch(),nowvalue);
/*chart*/
chart->legend()->hide();
chart->setTitle("Dati filtrati durante il periodo temporale");
chart->addAxis(axisY, Qt::AlignLeft);
chart->addAxis(axisX, Qt::AlignBottom);
chart->addSeries(series);
chartView = new QChartView(chart);
ui->verticalLayout->addWidget(chartView);
我不明白为什么不显示值。
我不知道出了什么问题。