Sync charts with custom scale.
Hi. I have two charts with one common axis. The axis is time scale. I need to show time in “hh:mm:ss.zzz†format. So I created inheritor from QwtDrawScale and overloaded method label() (like in CPUplot example). I assigned objects of this inheritor to both of the charts. The second chart is located below the first, so I don’t want to show xBottom axis for the first chart. It means that I disable the axis for the plot. But in this case lines of the grids are not matched. I guess I should do something with QwtScaleDiv class, but I can’t understand what. Thank you for any help.
Re: Sync charts with custom scale.
Check the plotmatrix example.
Uwe
3 Attachment(s)
Re: Sync charts with custom scale.
Do you mean assign QwtScaleDiv from lower plot to upper plot? I tried it and there is a result:
Attachment 11596
If I disable the axis of the upper chart I have:
Attachment 11597
But I need:
Attachment 11598
Without labels under first chart.
Re: Sync charts with custom scale.
Could you explain, why the grids doesn't match when I hide labels?
Re: Sync charts with custom scale.
The space, that is needed for the tick labels, has an effect on the position of the ticks. On the left side it is possible to move parts of the label below the left scale, but as there is none on the right ...
How to solve it depends on the details of your application: f.e you could choose an alignment like in the cpuplot example, where the part of the tick labels right from the tick is smaller, than the canvas margin.
Uwe
Re: Sync charts with custom scale.
I figured out from Qwt sources that grid drawing depends on QwtScaleMap object. So I decided to override "canvasMap" method of QwtPlot class and pass the scale widget of another plot with visible scale.
Code:
void OneAxisDisabledPlot
::setDisabledAxis(int axisId,
QwtScaleWidget* baseWidget
) {
enableAxis(axisId, false);
m_disabledAxis = axisId;
m_baseScaleWidget = baseWidget;
}
bool OneAxisDisabledPlot::isAxisDisabled(int axisId) const
{
return m_disabledAxis == axisId;
}
QwtScaleMap OneAxisDisabledPlot
::canvasMap(int axisId
) const {
if(!canvas())
return map;
map.setTransformation(axisScaleEngine(axisId)->transformation());
map.setScaleInterval(sd.lowerBound(), sd.upperBound());
const QwtScaleWidget *s
= isAxisDisabled
(axisId
) ? m_baseScaleWidget
: axisWidget
(axisId
);
if(axisEnabled(axisId) || isAxisDisabled(axisId))
{
if(axisId == yLeft || axisId == yRight)
{
double y = s->y() + s->startBorderDist() - canvas()->y();
double h = s->height() - s->startBorderDist() - s->endBorderDist();
map.setPaintInterval(y + h, y);
}
else
{
double x = s->x() + s->startBorderDist() - canvas()->x();
double w = s->width() - s->startBorderDist() - s->endBorderDist();
map.setPaintInterval(x, x + w);
}
}
else
{
const QRect &canvasRect
= canvas
()->contentsRect
();
if(axisId == yLeft || axisId == yRight)
{
int top = 0;
if(!plotLayout()->alignCanvasToScale(xTop))
top = plotLayout()->canvasMargin(xTop);
int bottom = 0;
if(!plotLayout()->alignCanvasToScale(xBottom))
bottom = plotLayout()->canvasMargin(xBottom);
map.setPaintInterval(canvasRect.bottom() - bottom,
canvasRect.top() + top);
}
else
{
int left = 0;
if(!plotLayout()->alignCanvasToScale(yLeft))
left = plotLayout()->canvasMargin(yLeft);
int right = 0;
if(!plotLayout()->alignCanvasToScale(yRight))
right = plotLayout()->canvasMargin(yRight);
map.setPaintInterval(canvasRect.left() + left,
canvasRect.right() - right);
}
}
return map;
}