Chart width
Chart width
Hi,
How can I determine the width of the actual drawing area of the chart? (not the panel and not including labels, margins, etc...)
I tried:
Rectangle rc = tChart1.Chart.ChartRect;
int width = rc.Width;
But it does not seem to be correct.
Thanks!
How can I determine the width of the actual drawing area of the chart? (not the panel and not including labels, margins, etc...)
I tried:
Rectangle rc = tChart1.Chart.ChartRect;
int width = rc.Width;
But it does not seem to be correct.
Thanks!
Hi Gp
ChartRect doesn't have valid values untill the chart is fully drawn. You can retrieve ChartRect's width in the AfterDraw event after the chart has been fully repainted (see the bitmap trick).
ChartRect doesn't have valid values untill the chart is fully drawn. You can retrieve ChartRect's width in the AfterDraw event after the chart has been fully repainted (see the bitmap trick).
Code: Select all
private void Form1_Load(object sender, EventArgs e)
{
bar1.FillSampleValues(7);
//Trick to force the chart being internally repainted so that ChartRect has valid values.
Bitmap bmp = tChart1.Bitmap;
}
private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
Rectangle rc = tChart1.Chart.ChartRect;
int width = rc.Width;
tChart1.Header.Text = width.ToString();
}
Hi Gp
You can remove the "Bitmap bmp = tChart1.Bitmap;" line. The problem was that Tchart header wasn't updated.
If you need the width before the bar is drawn, you can use TeeChart's BeforeDrawAxes or BeforeDrawSeries events.
You can remove the "Bitmap bmp = tChart1.Bitmap;" line. The problem was that Tchart header wasn't updated.
If you need the width before the bar is drawn, you can use TeeChart's BeforeDrawAxes or BeforeDrawSeries events.
Code: Select all
private void Form1_Load(object sender, EventArgs e)
{
bar1.FillSampleValues(7);
}
private void tChart1_BeforeDrawSeries(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
Rectangle rc = tChart1.Chart.ChartRect;
label1.Text = rc.Width.ToString();
//Put your bar settings code here
bar1.BarWidthPercent = 100;
}
I have found that the BeforeDrawSeries and BeforeDrawAxis events are called AFTER the code that sets the custom bar size (CustomBar.DoCalcBarWidth()). So I need to set my bar size in BeforeDraw.
However, I have found that sometimes when unzooming, the chart bounds are not set correctly the first time (and animated zoom is off). This results in a real messy chart until something is done to redraw the chart again.
What would be the reason that the chart bounds are not set correctly when unzoomed?
However, I have found that sometimes when unzooming, the chart bounds are not set correctly the first time (and animated zoom is off). This results in a real messy chart until something is done to redraw the chart again.
What would be the reason that the chart bounds are not set correctly when unzoomed?
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Gp,
Could you please send us a simple example project we can run "as-is" to reproduce the problem here?
You can post your files at news://www.steema.net/steema.public.attachments newsgroup.
Thanks in advance.
Could you please send us a simple example project we can run "as-is" to reproduce the problem here?
You can post your files at news://www.steema.net/steema.public.attachments newsgroup.
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Gp,
Thanks for the example. I noticed that you are using a TeeChart for .NET v2 build from August 2005, please notice that several maintenance releases have been published since then. I tested your project using the latest maintenance release available at the client area and couldn't reproduce the problem. Could you please uninstall your current TeeChart version, install the latest version (December 2006 build) and check if the problem still occurs? If so please let us know the exact steps we should follow to reproduce it.
Thanks in advance.
Thanks for the example. I noticed that you are using a TeeChart for .NET v2 build from August 2005, please notice that several maintenance releases have been published since then. I tested your project using the latest maintenance release available at the client area and couldn't reproduce the problem. Could you please uninstall your current TeeChart version, install the latest version (December 2006 build) and check if the problem still occurs? If so please let us know the exact steps we should follow to reproduce it.
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Gp,
Yes, and I couldn't reproduce it with that version either following the steps you mentioned at the newsgroup. Could you please let us know the exact steps we should follow or post a screen-shot at the newsgroups showing the problem?
Thanks in advance.
Yes, and I couldn't reproduce it with that version either following the steps you mentioned at the newsgroup. Could you please let us know the exact steps we should follow or post a screen-shot at the newsgroups showing the problem?
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Gp,
Thanks for the document. Now I could reproduce the problem here and added it (TF02012024) to our defect list to be fixed for future releases. In the meantime, a workaround is internally repaint the chart in the UndoneZoom event, for example:
Thanks for the document. Now I could reproduce the problem here and added it (TF02012024) to our defect list to be fixed for future releases. In the meantime, a workaround is internally repaint the chart in the UndoneZoom event, for example:
Code: Select all
private void tChart1_UndoneZoom(object sender, System.EventArgs e)
{
//Workaround
Bitmap bmp = tChart1.Bitmap;
}
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Correction - this workaround doesn't work in all cases. If the bar data is cleared, the first time data is added and the chart is redrawn the problem occurs. This makes it so I cannot use a bar chart.
Add a button that clears the bar data to the project I had posted earlier and you will see the problem.
Add a button that clears the bar data to the project I had posted earlier and you will see the problem.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Gp,
I could reproduce the problem here but it is solved not calling setBarWidth() method in the bar1_AfterDrawValues event.
I'll post your example modified to work properly at the newsgroups. We have also changed the way CustomBarWidth is calculated to something similar at what's done internally in TeeChart.
I could reproduce the problem here but it is solved not calling setBarWidth() method in the bar1_AfterDrawValues event.
I'll post your example modified to work properly at the newsgroups. We have also changed the way CustomBarWidth is calculated to something similar at what's done internally in TeeChart.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |