更新代码
This commit is contained in:
@@ -15,9 +15,9 @@ frmDate::~frmDate()
|
||||
|
||||
void frmDate::initForm()
|
||||
{
|
||||
#ifndef qcustomplot_v1_3
|
||||
// set locale to english, so we get english month names:
|
||||
ui->customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom));
|
||||
|
||||
// seconds of current time, we'll use it as starting point in time for data:
|
||||
double now = QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000.0;
|
||||
srand(8); // set the random seed, so we always get the same random data
|
||||
@@ -40,21 +40,26 @@ void frmDate::initForm()
|
||||
}
|
||||
ui->customPlot->graph()->data()->set(timeData);
|
||||
}
|
||||
|
||||
// configure bottom axis to show date instead of number:
|
||||
QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime);
|
||||
dateTicker->setDateTimeFormat("d. MMMM\nyyyy");
|
||||
ui->customPlot->xAxis->setTicker(dateTicker);
|
||||
|
||||
// configure left axis text labels:
|
||||
QSharedPointer<QCPAxisTickerText> textTicker(new QCPAxisTickerText);
|
||||
textTicker->addTick(10, "a bit\nlow");
|
||||
textTicker->addTick(50, "quite\nhigh");
|
||||
ui->customPlot->yAxis->setTicker(textTicker);
|
||||
|
||||
// set a more compact font size for bottom and left axis tick labels:
|
||||
ui->customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 8));
|
||||
ui->customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
|
||||
|
||||
// set axis labels:
|
||||
ui->customPlot->xAxis->setLabel("Date");
|
||||
ui->customPlot->yAxis->setLabel("Random wobbly lines value");
|
||||
|
||||
// make top and right axes visible but without ticks and labels:
|
||||
ui->customPlot->xAxis2->setVisible(true);
|
||||
ui->customPlot->yAxis2->setVisible(true);
|
||||
@@ -62,12 +67,13 @@ void frmDate::initForm()
|
||||
ui->customPlot->yAxis2->setTicks(false);
|
||||
ui->customPlot->xAxis2->setTickLabels(false);
|
||||
ui->customPlot->yAxis2->setTickLabels(false);
|
||||
|
||||
// set axis ranges to show all data:
|
||||
ui->customPlot->xAxis->setRange(now, now + 24 * 3600 * 249);
|
||||
ui->customPlot->yAxis->setRange(0, 60);
|
||||
|
||||
// show legend with slightly transparent background brush:
|
||||
ui->customPlot->legend->setVisible(true);
|
||||
ui->customPlot->legend->setBrush(QColor(255, 255, 255, 150));
|
||||
ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user