|
Trouble with multiple Y axes |
Posted by MikeP on Nov-26-2014 05:26 |
|
Hello Peter.
I'm trying to add functionality to display one of 2 left-aligned y-axes, but seem to have
a problem when the 'primary' y-axis is rendered transparently. Hopefully
the following code segments will help demonstrate what I'm trying to do:
XYChart* c = new XYChart(...);
c->yAxis()->setLabelFormat("{value|,.-$}");
c->yAxis()->setMinTickInc(1);
c->yAxis()->setRounding(false, false);
c->yAxis()->setLinearScale(m_zoom * minVal, m_zoom * maxVal);
Axis* altAxis = c->addAxis(Chart::Left, 0);
altAxis->setLabelFormat("{value|,.-$}");
altAxis->setMinTickInc(1);
altAxis->setRounding(false, false);
altAxis->setLinearScale(m_zoom2 * minVal, m_zoom2 * maxVal);
if( showAltAxis )
{
c->yAxis()->setColors(Chart::Transparent, Chart::Transparent, Chart::Transparent, Chart::Transparent);
altAxis->setColors(Chart::LineColor, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF);
}
else
{
c->yAxis()->setColors(Chart::LineColor, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF);
altAxis->setColors(Chart::Transparent, Chart::Transparent, Chart::Transparent, Chart::Transparent);
}
...
c->setPlotArea(plotAreaX, plotAreaY, plotAreaW, plotAreaH, 0x808080);
...
c->layoutAxes(); // manually layout axes for potential axis re-labeling
...
c->packPlotArea(packLeftX, packTopY, packRightX, packBottomY);
Basically I only want 1 left-aligned y-axis to display depending on the showAltAxis flag
(eg, user holding down SHIFT key). This works fine when showAltAxis is
false (ie, using c->yAxis()) but not when showAltAxis is true (ie, using altAxis). Please
see the attached images.
It's almost as if, when c->yAxis() is completely transparent, the chart thinks there is no
left-aligned y-axis at all.
Any help you can provide would be appreciated.
|
Re: Trouble with multiple Y axes |
Posted by Peter Kwan on Nov-26-2014 23:39 |
|
Hi MikeP,
The issue is caused by the tranpsarent labels.
Normally, ChartDirector needs to evaluating the "{value|,.-$}" to determine the text of all
the labels, then then load the required font and layout and render the text. As these
operations consume non-negligible CPU and memory, if the label color is transparent,
ChartDirector would not perform the above steps, and so it would not know the exact label
text and size.
For your case, one method is to make the labels non-transparent. You can either set the
label color to the same color as the background, or set the label color is an almost
transparent color, such as 0xfe888888. The text is essentially invisible if an almost
transparent color is used, but ChartDirector would still perform all the steps to format and
layout the labels, so the axis width will be as if the axis is visible.
Hope this can help.
Regards
Peter Kwan |
Re: Trouble with multiple Y axes |
Posted by MikeP on Nov-27-2014 00:08 |
|
Hi Peter.
I tried setting the primary axis label color to the background color, but I think those labels
are being rendered in front of the alt axis labels because I can see them (primary labels)
obscuring the alt axis labels. I will try the 'almost invisible' value, though.
One thing I noticed, even if I try to render both axes at the same time, the chart layout
doesn't seem to account for the alt axis labels. Said another way, if I am rendering both
the primary and alt axes, I would expect the plot area to get smaller to accommodate both
axes' labels, but this doesn't seem to happen. It only appears to adjust enough to ensure
the primary yAxis labels are visible. Am I doing something wrong in that regard? Does the
library code not account for axes other than the yAxis and yAxis2 when adjusting the plot
area width? Please see attached images which will hopefully show what I mean.
Your help would be appreciated.
Thanks.
Mike
|
Re: Trouble with multiple Y axes |
Posted by Peter Kwan on Nov-27-2014 02:30 |
|
Hi MikeP,
As according to the ChartDirector documentation, the packPlotArea "only adjusts for the
thickness of the primary and secondary axes" (the yAxis, yAxis2, xAxis and xAxis2). It will
not consider the other extra axis. To handle the extra axis, the documentation suggests to
use Axis.getThickness to obtain the axis thickness and adjust the parameters in the
packPlotArea (eg. reserving more space) accordingly. (Note: you need to call
XYChart.layoutAxes first before you can use Axis.getThickness.)
Hope this can help.
Regards
Peter Kwan |
Re: Trouble with multiple Y axes |
Posted by MikeP on Nov-27-2014 03:31 |
|
Thank you very much for the help, Peter.
I had read the docs for setPlotArea when I should have been using those for packPlotArea.
Also, using the 0xfeffffff worked as expected.
Thanks again! |
|