Uwe,
Thank you very much for the reply.
But I'm still very confused.
plot.
setAxisScale( QwtPlot::xBottom, QwtDate
::toDouble( start
), QwtDate
::toDouble( end
) ,
24 * 3600 * 1000 );
plot.setAxisScale( QwtPlot::xBottom, QwtDate::toDouble( start ), QwtDate::toDouble( end ) , 24 * 3600 * 1000 );
To copy to clipboard, switch view to plain text mode
Makes no difference.
As far as I understand, the interval type seem to differ?
I was using seconds as the smallest interval.
I've set the setDateFormat as Days, which is what I would rather use.
auto * scaleDraw = new QwtDateScaleDraw( Qt::UTC );
scaleDraw
->setDateFormat
( QwtDate
::Day,
QString("dd-mm-yyyy") );
auto * scaleDraw = new QwtDateScaleDraw( Qt::UTC );
scaleDraw->setDateFormat( QwtDate::Day, QString("dd-mm-yyyy") );
To copy to clipboard, switch view to plain text mode
When I try to to set the axis starting date, by using seconds elapsed since the unix epoch:
plot.
setAxisScale( QwtPlot::xBottom, start.
toTime_t(), end.
toTime_t() ,
24 * 3600 * 30 );
plot.setAxisScale( QwtPlot::xBottom, start.toTime_t(), end.toTime_t() , 24 * 3600 * 30 );
To copy to clipboard, switch view to plain text mode
The interval is wrong, because what I see is a starding date a few seconds after the unix epoch.
Yet
QwtPlot::setAxisScale (int axisId,
double min,
double max,
double step
=0)
QwtPlot::setAxisScale (int axisId, double min, double max, double step=0)
To copy to clipboard, switch view to plain text mode
asks for my minimal and maximum value, and the step size, so my minimal step size are the days elapsed from start date since the epoch, and the max size are the days elapsed from end date since the epoch.
So, I re-factored by trying to use days only this time:
QDateTime epoch ( QDate( 1970, 1, 1 ), QTime(0,0,0) );
To copy to clipboard, switch view to plain text mode
and then tried to reset the axis, to use days, incremented monthly (every 30 days label):
plot.
setAxisScale( QwtPlot::xBottom, epoch.
daysTo( start
), epoch.
daysTo( end
) ,
30 );
plot.setAxisScale( QwtPlot::xBottom, epoch.daysTo( start ), epoch.daysTo( end ) , 30 );
To copy to clipboard, switch view to plain text mode
To my suprise, I am still getting the epoch in 1970, although I have set it to days, the increment appears to be in miliseconds, as the y axis labels increment only by ms.
Which implies that I cannot set directly the DateScale to use days, because it uses some other interval?
I don't want the second or milliseconds to be the smallest interval, but only a days. How do I achieve that?
QwtDate::IntervalType
QwtDate::IntervalType
To copy to clipboard, switch view to plain text mode
Is protected. How do I use it without creating a class that inherits from it? Or is that the way it must be used?
Finally, I populate the plot values, using days elapsed like so:
for ( const auto & p: sma )
{
points <<
QPointF( epoch.
daysTo( date
), p.
first );
}
QPolygonF points;
for ( const auto & p: sma )
{
QDateTime date ( QDate( p.second.year(), p.second.month(), p.second.day() ), QTime(0,0,0) );
points << QPointF( epoch.daysTo( date ), p.first );
}
To copy to clipboard, switch view to plain text mode
Which draws a correct curve of my data.
Thank you very much for your help!
#EDIT
Nevermind, I finally figured it out, I had to multiply by the amount of milliseconds in a day, like so:
double x = 86400000.;
plot.
setAxisScale( QwtPlot::xBottom, epoch.
daysTo( start
) * x, epoch.
daysTo( end
) * x ,
30 * x
);
...
for ( const auto & p: sma )
{
points <<
QPointF( epoch.
daysTo( date
) * x, p.
first );
}
double x = 86400000.;
plot.setAxisScale( QwtPlot::xBottom, epoch.daysTo( start ) * x, epoch.daysTo( end ) * x , 30 * x );
...
for ( const auto & p: sma )
{
QDateTime date ( QDate( p.second.year(), p.second.month(), p.second.day() ), QTime(0,0,0) );
points << QPointF( epoch.daysTo( date ) * x, p.first );
}
To copy to clipboard, switch view to plain text mode
This fixed botht he labels, and the date alignment.
Bookmarks