Page 1 of 1
Chart width
Posted: Sat Jan 06, 2007 12:39 am
by 8128589
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!
Posted: Mon Jan 08, 2007 10:08 am
by 9348258
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();
}
Posted: Mon Jan 08, 2007 6:40 pm
by 8128589
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!
Posted: Tue Jan 09, 2007 8:57 am
by 9348258
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;
}
Posted: Wed Jan 10, 2007 12:37 am
by 8128589
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?
Posted: Wed Jan 10, 2007 12:07 pm
by narcis
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.
Posted: Wed Jan 10, 2007 5:25 pm
by 8128589
I have posted a project to the newsgroup.
Posted: Thu Jan 11, 2007 9:58 am
by narcis
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.
Posted: Thu Jan 11, 2007 6:45 pm
by 8128589
Did you test it with the TeeChart version I included with the project?
Posted: Fri Jan 12, 2007 8:50 am
by narcis
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.
Posted: Fri Jan 12, 2007 5:13 pm
by 8128589
I've posted a Word document with duplication steps and screenshots.
Posted: Mon Jan 15, 2007 12:37 pm
by narcis
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;
}
Posted: Tue Jan 16, 2007 5:09 pm
by 8128589
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.
Posted: Wed Jan 17, 2007 10:32 pm
by 8128589
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.
Posted: Fri Jan 19, 2007 10:22 am
by narcis
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.