QCustomPlot Discussion and Comments

QCPAxisTickerTime vs QCPAxisTickerDateTime in realtime plotReturn to overview

I want to set the xAxis show the current system time in %h%m%s format.
In old version following code works fine

//plot setup
//realtime plot
 double nowtime=QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
ui->cpuwidget->xAxis->setRange(nowtime, 60, Qt::AlignRight);

But now in 2.0 version,i have read the QCPAxisTickerTime and QCPAxisTickerDateTime documentation,QCPAxisTickerDateTime says if want to display small tick time should use QCPAxisTickerTime ,but QCPAxisTickerTime now seems can't works fine in following code

QSharedPointer<QCPAxisTickerTime > timeTicker(new QCPAxisTickerTime);

double nowtime = QDateTime::currentDateTime().toTime_t();
ui.widget_power->xAxis->setRange(nowtime, 60, Qt::AlignRight);
the result is that xAxis shows time with large number (maybe ms value from January 1, 1970, 00:00 UTC)

so how to make the xAxis show the current system time in %h%m%s or %m%s format?

For now ,i use QCPAxisTickerTime with following code to slove my request
double nowtime = QTime::currentTime().msecsSinceStartOfDay() / 1000;

In principle your solution is good, and that's what QCPAxisTickerTime is for: a time axis with an arbitrary zero-point (in your case, the start of the current day).

The QCPAxisTickerDateTime however, has a calendar fixed zero with respect to its input: 01.01.1970 00:00 UTC (epoch). So QCPAxisTickerDateTime can not only display days/hours/minutes but also knows about months and years, and differing day numbers per month, etc.

Of course, the inputs differ:
If you input the number of seconds since 01.01.1970 (which you did in your first post, by using QDateTime::currentDateTime().toTime_t();) then QCPAxisTickerDateTime will output the expected date and time. On the other hand QCPAxisTickerTime will simply consume that long time span in its highest time unit given in its format (e.g. the hour) and thus produce very large numbers.

If you wish to only have hour and minute display with QCPAxisTickerDateTime, simply set its format accordingly to something like "hh:mm:ss", with setDateTimeFormat.