{
public:
TimeScaleDraw( )
{
setLabelRotation(0);
setLabelAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
setSpacing(20);
}
virtual QwtText label
( double v
) const {
time = time.fromTime_t(v);
QDate date
(2010,
11,
27);
time.setDate(date);
qDebug()<<"v"<<v;
return time.toString("yyyy-MM-dd-hh-mm-ss"); //MM is important to display months correctly, mm does not work
}
{
setAutoReplot( false );
canvas->setBorderRadius( 10 );
setCanvas( canvas );
plotLayout()->setAlignCanvasToScales( true );
legend->setDefaultItemMode( QwtLegendData::Checkable );
insertLegend
( legend,
QwtPlot::RightLegend );
setAxisTitle
( QwtPlot::xBottom,
"Date:Time[yyyy-mm-dd-hh-mm-ss]" );
double x1 = QwtDate::toDouble(date1);
double x2 = QwtDate::toDouble(date2);
double stepSize = 3600;
qDebug()<<date1<<date2<<QwtDate::toDateTime(x1, Qt::LocalTime)<<x1;
//QwtDateScaleDraw *scaleDraw = new DateScaleDraw(Qt::UTC);
//setAxisScaleDraw( QwtPlot::xBottom, scaleDraw );
setAxisScaleDraw
( QwtPlot::xBottom,
new TimeScaleDraw
);
QwtDateScaleEngine *scaleEngine = new QwtDateScaleEngine();
scaleEngine->autoScale(170, x1, x2, stepSize);
//setAxisScaleEngine( QwtPlot::xBottom, scaleEngine );
//setAxisScale( QwtPlot::xBottom, 0, 170 );
setAxisLabelRotation
( QwtPlot::xBottom,
-50.0 );
setAxisLabelAlignment
( QwtPlot::xBottom, Qt
::AlignLeft | Qt
::AlignBottom );
.....
}
class TimeScaleDraw: public QwtScaleDraw
{
public:
TimeScaleDraw( )
{
setTickLength(QwtScaleDiv::MajorTick, 7);
setTickLength(QwtScaleDiv::MinorTick, 24);
setTickLength(QwtScaleDiv::MediumTick, 0);
setLabelRotation(0);
setLabelAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
setSpacing(20);
}
virtual QwtText label( double v ) const
{
QDateTime time;
time = time.fromTime_t(v);
QDate date (2010, 11, 27);
time.setDate(date);
qDebug()<<"v"<<v;
return time.toString("yyyy-MM-dd-hh-mm-ss"); //MM is important to display months correctly, mm does not work
}
Plot::Plot(QWidget *parent ): QwtPlot( parent )
{
setAutoReplot( false );
QwtPlotCanvas *canvas = new QwtPlotCanvas();
canvas->setBorderRadius( 10 );
setCanvas( canvas );
plotLayout()->setAlignCanvasToScales( true );
QwtLegend *legend = new QwtLegend;
legend->setDefaultItemMode( QwtLegendData::Checkable );
insertLegend( legend, QwtPlot::RightLegend );
setAxisTitle( QwtPlot::xBottom, "Date:Time[yyyy-mm-dd-hh-mm-ss]" );
QDateTime date1(QDate(2010,11,27), QTime(0,0,0));
QDateTime date2(QDate(2010,12,3), QTime(23,0,0));
double x1 = QwtDate::toDouble(date1);
double x2 = QwtDate::toDouble(date2);
double stepSize = 3600;
qDebug()<<date1<<date2<<QwtDate::toDateTime(x1, Qt::LocalTime)<<x1;
//QwtDateScaleDraw *scaleDraw = new DateScaleDraw(Qt::UTC);
//setAxisScaleDraw( QwtPlot::xBottom, scaleDraw );
setAxisScaleDraw( QwtPlot::xBottom, new TimeScaleDraw);
QwtDateScaleEngine *scaleEngine = new QwtDateScaleEngine();
scaleEngine->autoScale(170, x1, x2, stepSize);
//setAxisScaleEngine( QwtPlot::xBottom, scaleEngine );
//setAxisScale( QwtPlot::xBottom, 0, 170 );
setAxisLabelRotation( QwtPlot::xBottom, -50.0 );
setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom );
.....
}
To copy to clipboard, switch view to plain text mode
Bookmarks