[英]Custom tick step on QCustomPlot - QT
我是 QCustomPlot 的新手,但我無法創建 TickStep 的自定義大小。
現在,我有這個情節,(時間是從 6:00 到另一天的 6:00)。
我想要的 X 軸標簽是什么:
我嘗試使用 setTickStep 但沒有成功。
QVector<double> x(96), y(96);
for (int i=0; i<95; ++i)
{
x[i] = i*900+22500;
y[i] = someValues loaded from db
}
ui->customPlot->addGraph();
ui->customPlot->setBackground(QBrush(QColor(239, 239, 239, 255)));
ui->customPlot->graph(0)->setData(x, y);
ui->customPlot->xAxis->setRange(21600, 108000);
ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
ui->customPlot->xAxis->setDateTimeFormat("h:mm");
//ui->customPlot->xAxis->setTickStep(7200);
在設置自定義刻度步驟之前,您錯過了一件事。 默認情況下,軸上啟用了名為:自動刻度步驟的功能,因此您需要先禁用它。
QVector<double> x(96), y(96);
for (int i=0; i<95; ++i)
{
x[i] = i*900+22500;
y[i] = i; // some values not from database
}
ui->customPlot->addGraph();
ui->customPlot->setBackground(QBrush(QColor(239, 239, 239, 255)));
ui->customPlot->graph(0)->setData(x, y);
ui->customPlot->xAxis->setRange(21600, 108000);
ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
ui->customPlot->xAxis->setDateTimeFormat("h:mm");
ui->customPlot->xAxis->setAutoTickStep(false); // <-- disable to use your own value
ui->customPlot->xAxis->setTickStep(7200);
有和沒有附加行的結果:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.