Aligning multiple charts with custom labels
Aligning multiple charts with custom labels
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.
- Attachments
-
- graphs.png (85.86 KiB) Viewed 13702 times
Re: Aligning multiple charts with custom labels
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.
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.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Aligning multiple charts with custom labels
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
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:
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) { }
});
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Aligning multiple charts with custom labels
chart1.getAxes().getLeft().getSizeLabels(); works for me, just took some time to find the right function