G'day All,
I've been experimenting with the Qwt histogram and cpuplot examples trying to produce a chart on a time axis. The labels on my x axis are rotated dates. The rightmost date was slightly truncated at its top-right extremity but I fixed that with a bit of code lifted from the cpuplot example. The left most label in my graph (see blue box below) is badly truncated. The time labels in the cpuplot example are not similarly truncated.
The plot layout code looks like:
plot.setMargin(5);
plot.
setCanvasBackground(QColor(Qt
::white));
plot.setTitle("Hours by Month");
plot.
setAxisTitle(QwtPlot::yLeft,
"Hours");
plot.
setAxisTitle(QwtPlot::xBottom,
"Date");
plot.
setAxisScaleDraw(QwtPlot::xBottom,
new TimeScaleDraw
(QDate::currentDate()));
plot.
setAxisLabelRotation(QwtPlot::xBottom,
-50.0);
plot.
setAxisLabelAlignment(QwtPlot::xBottom, Qt
::AlignLeft | Qt
::AlignBottom);
// From cpuplot example to stop rightmost label being truncated
scaleWidget->setMinBorderDist(0, fmh / 2);
QwtPlot plot;
plot.setMargin(5);
plot.setCanvasBackground(QColor(Qt::white));
plot.setTitle("Hours by Month");
plot.setAxisTitle(QwtPlot::yLeft, "Hours");
plot.setAxisTitle(QwtPlot::xBottom, "Date");
plot.setAxisScaleDraw(QwtPlot::xBottom,
new TimeScaleDraw(QDate::currentDate()));
plot.setAxisLabelRotation(QwtPlot::xBottom, -50.0);
plot.setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
// From cpuplot example to stop rightmost label being truncated
QwtScaleWidget *scaleWidget = plot.axisWidget(QwtPlot::xBottom);
const int fmh = QFontMetrics(scaleWidget->font()).height();
scaleWidget->setMinBorderDist(0, fmh / 2);
To copy to clipboard, switch view to plain text mode
a bunch of code building QwtScaleDiv tick data, then
plot.
setAxisScaleDiv(QwtPlot::xBottom, sd
);
QwtScaleDiv sd(-(double)(numValues+1), 1.0, vl);
plot.setAxisScaleDiv(QwtPlot::xBottom, sd);
To copy to clipboard, switch view to plain text mode
followed by an essentially unmodified (colours aside) histogram example.
I thought it might be a z-order issue with the y-axis scale overwriting, but I couldn't find a way to change this. What do I need to tweak to sort this out?
Regards,
Chris
Qwt 5.2.0, Qt 4.5.1, Linux
Bookmarks