Aligning multiple charts with custom labels

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
mts
Newbie
Newbie
Posts: 18
Joined: Fri Apr 29, 2011 12:00 am

Aligning multiple charts with custom labels

Post by mts » Wed Nov 02, 2011 3:11 pm

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
graphs.png (85.86 KiB) Viewed 2504 times

Yeray
Site Admin
Site Admin
Posts: 8719
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Aligning multiple charts with custom labels

Post by Yeray » Thu Nov 03, 2011 8:28 am

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

mts
Newbie
Newbie
Posts: 18
Joined: Fri Apr 29, 2011 12:00 am

Re: Aligning multiple charts with custom labels

Post by mts » Thu Nov 03, 2011 2:53 pm

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()....

Yeray
Site Admin
Site Admin
Posts: 8719
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Aligning multiple charts with custom labels

Post by Yeray » Fri Nov 04, 2011 1:03 pm

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) { }
		});
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

mts
Newbie
Newbie
Posts: 18
Joined: Fri Apr 29, 2011 12:00 am

Re: Aligning multiple charts with custom labels

Post by mts » Wed Nov 09, 2011 3:29 pm

chart1.getAxes().getLeft().getSizeLabels(); works for me, just took some time to find the right function

Post Reply