Chart width

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Gp
Newbie
Newbie
Posts: 43
Joined: Thu Jan 13, 2005 5:00 am

Chart width

Post by Gp » Sat Jan 06, 2007 12:39 am

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!

Edu
Advanced
Posts: 206
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia

Post by Edu » Mon Jan 08, 2007 10:08 am

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

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();
        }
Best Regards,
Edu

Steema Support Central
http://support.steema.com/

Gp
Newbie
Newbie
Posts: 43
Joined: Thu Jan 13, 2005 5:00 am

Post by Gp » Mon Jan 08, 2007 6:40 pm

So is there any other way to calculate the chart width before drawing, such as subtracting the margin or label sizes?

What I am doing is setting the bar width to match a time interval. So of course I need to set the width before the bar is drawn!

Edu
Advanced
Posts: 206
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia

Post by Edu » Tue Jan 09, 2007 8:57 am

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.

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;
}

Best Regards,
Edu

Steema Support Central
http://support.steema.com/

Gp
Newbie
Newbie
Posts: 43
Joined: Thu Jan 13, 2005 5:00 am

Post by Gp » Wed Jan 10, 2007 12:37 am

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?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Jan 10, 2007 12:07 pm

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Gp
Newbie
Newbie
Posts: 43
Joined: Thu Jan 13, 2005 5:00 am

Post by Gp » Wed Jan 10, 2007 5:25 pm

I have posted a project to the newsgroup.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Jan 11, 2007 9:58 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Gp
Newbie
Newbie
Posts: 43
Joined: Thu Jan 13, 2005 5:00 am

Post by Gp » Thu Jan 11, 2007 6:45 pm

Did you test it with the TeeChart version I included with the project?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Jan 12, 2007 8:50 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Gp
Newbie
Newbie
Posts: 43
Joined: Thu Jan 13, 2005 5:00 am

Post by Gp » Fri Jan 12, 2007 5:13 pm

I've posted a Word document with duplication steps and screenshots.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Jan 15, 2007 12:37 pm

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:

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
Image Image Image Image Image Image
Instructions - How to post in this forum

Gp
Newbie
Newbie
Posts: 43
Joined: Thu Jan 13, 2005 5:00 am

Post by Gp » Tue Jan 16, 2007 5:09 pm

Thanks, this workaround seems to work for me. I also had to put this fix into the tChart1_Zoomed callout. The bar widths were also not being set correctly the first when zoomed.

Gp
Newbie
Newbie
Posts: 43
Joined: Thu Jan 13, 2005 5:00 am

Post by Gp » Wed Jan 17, 2007 10:32 pm

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.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Jan 19, 2007 10:22 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply