Page 1 of 1
Right-aligned legend has no margin
Posted: Sat Feb 23, 2013 4:46 pm
by 17064597
My right-aligned legend is always 0 pixels from the right side of my chart. I would like to add a couple of pixels spacing, but can't figure out how. Looking through the source code, it seems no such feature is available.
Any ideas?
Re: Right-aligned legend has no margin
Posted: Mon Feb 25, 2013 1:28 pm
by yeray
Hi,
You can add some Horizontal Margin between the legend and the Chart with:
Code: Select all
tChart1.getLegend().setHorizMargin(10);
Note if your Legend is TOP/BOTTOM aligned, you'll have to use setVertMargin instead:
Code: Select all
tChart1.getLegend().setAlignment(LegendAlignment.BOTTOM);
tChart1.getLegend().setVertMargin(10);
Re: Right-aligned legend has no margin
Posted: Tue Feb 26, 2013 10:37 pm
by 17064597
Thanks. I tried that, but it doesn't work. However, I found a workaround:
_chart.setLegendResolver(new LegendAdapter() {
@Override
public Rectangle getBounds(Legend legend, Rectangle rectangle) {
return new Rectangle(rectangle.x, rectangle.y, rectangle.width - 6, rectangle.height);
};
});
Though, I would still consider this a bug. setHorizMargin has no effect (Android 4.2.2).
Re: Right-aligned legend has no margin
Posted: Wed Feb 27, 2013 2:39 pm
by yeray
Hello,
It does work for me with the latest TeeChart Java for Android, v3.2012.1120:
Code: Select all
tChart1.getAspect().setView3D(false);
tChart1.getHeader().setVisible(false);
Line line1 = new Line(tChart1.getChart());
line1.fillSampleValues();
tChart1.getLegend().setHorizMargin(100);
- device-2013-02-27-153349.png (17.55 KiB) Viewed 15322 times
Android emulator, v4.2.2
Re: Right-aligned legend has no margin
Posted: Fri Mar 15, 2013 4:56 pm
by 17064597
That looks like 100 pixels on the left. What about the right side? In my app it touches the border of the entire TChart view.
Re: Right-aligned legend has no margin
Posted: Mon Mar 18, 2013 2:41 pm
by yeray
Hi,
You can also set some Right Margin like follows:
Code: Select all
tChart1.getPanel().setMarginUnits(PanelMarginUnits.PIXELS);
tChart1.getPanel().setMarginRight(20);
If you still find any problem with it, please arrange a simple example project we can run as-is to reproduce the problem here.
Re: Right-aligned legend has no margin
Posted: Tue Mar 19, 2013 8:17 pm
by 17064597
setMarginRight did the trick! Thanks!