Page 1 of 1
Aligning multiple charts with custom labels
Posted: Wed Nov 02, 2011 3:11 pm
by 15359204
I have multiple charts displayed in a vertical row fashion, one on each row of a grid. The charts are all a history of data values over time so the X-axis on all is time and is the same, but the Y-axis varies. Some graph decimal numbers, other graph string states and I use custom labels. The problem is that my graphs automatically adjust the margins for the size of the labels, so the left sides of my grids are never aligned. I have tried using the getChart().getPanel().setMarginLeft(x) method but that just moves where the labels begin. I need the charts to line up, not the beginning of the labels. I've done some forum searching but can't find a solution. Please let me know what I should do. I attached a screenshot showing my graphs so you can see exactly what I mean about the alignment.
Re: Aligning multiple charts with custom labels
Posted: Thu Nov 03, 2011 8:28 am
by yeray
Hello,
You might be interested on looking at the discussions here:
http://www.teechart.net/support/viewtop ... =3&t=10620
http://www.teechart.net/support/viewtop ... =4&t=10004
They are from the VCL and .NET forum so the code may be a little bit different but it could help you if you are tying to align two charts.
In essence, you can't remove the margins internally calculated to fit the labels and titles but you can calculate the space taken for them and adjust the margins.
If you still have problems with it, please, don't hesitate to let us know.
Re: Aligning multiple charts with custom labels
Posted: Thu Nov 03, 2011 2:53 pm
by 15359204
This looks like it will work, but I am having trouble finding the MaxLabelsWidth property in java. Can you show me where it is from the TChart object? For example, chart1.getAxes().getLeft().getCustomLabels()....
Re: Aligning multiple charts with custom labels
Posted: Fri Nov 04, 2011 1:03 pm
by yeray
Hello,
Have you tried getLeft().maxLabelsWidth()?
Note that to get some axis values (like in this function), the chart needs to be painted once so the internal values have the correct values and some objects have initialized. So you may need to call it in the chartPainted event:
Code: Select all
tChart1.addChartPaintListener(new ChartPaintListener() {
@Override
public void seriesPainting(ChartDrawEvent e) { }
@Override
public void seriesPainted(ChartDrawEvent e) { }
@Override
public void chartPainting(ChartDrawEvent e) { }
@Override
public void chartPainted(ChartDrawEvent e) {
int maxl = tChart1.getAxes().getLeft().maxLabelsWidth();
tChart1.getHeader().setText(Integer.toString(maxl));
}
@Override
public void axesPainting(ChartDrawEvent e) { }
});
Re: Aligning multiple charts with custom labels
Posted: Wed Nov 09, 2011 3:29 pm
by 15359204
chart1.getAxes().getLeft().getSizeLabels(); works for me, just took some time to find the right function