Page 1 of 1

Legend resize

Posted: Tue Sep 22, 2009 4:27 pm
by 15653372
Hi,

When i try to resize a window with a legend in it, and there isnt enough room for the legend to draw completely i get the following error:

"Height must be non-negative"

at System.Windows.Rect.set_Height(Double value)
at Steema.TeeChart.WPF.Legend.ResizeChartRect(Rect& rect)
at Steema.TeeChart.WPF.Chart.DoDrawLegend(Rect& tmp)
at Steema.TeeChart.WPF.Chart.DrawTitlesAndLegend(DrawingContext g, Rect& tmp, Boolean BeforeSeries)
at Steema.TeeChart.WPF.Chart.InternalDraw(DrawingContext g, Boolean noTools)
at Steema.TeeChart.WPF.Chart.InternalDraw(DrawingContext g)
at Steema.TeeChart.WPF.TChart.Draw(DrawingContext g)
at Steema.TeeChart.WPF.TChart.OnRender(DrawingContext drawingContext)

Is there a way to remove the rectangle from the legend?

Re: Legend resize

Posted: Wed Sep 23, 2009 9:42 am
by yeray
Hi SPS,

Of course, you can hide it as follows:

Code: Select all

tChart1.Legend.Visible = false;

Re: Legend resize

Posted: Wed Sep 23, 2009 10:35 am
by 15653372
Yes i know, but i want the legend to be visisble. If i set the alignment of the legend to bottom or top i get the set_height error when resizing the window. If i set the alignment to right or left i dont get this error. So there seems to be a problem in the legend onpaint with the height of the rectangle. I Tried to make my own class for the legend and inherit from the legend and override the onpaint, but the chart legend doesnt have a setter.

Re: Legend resize

Posted: Wed Sep 23, 2009 11:22 am
by yeray
Hi SPS,

Could you please send us a picture showing the chart just before getting the error? I can reproduce the error but only in a chart as small as the ChartRect has been already disappeared.

Re: Legend resize

Posted: Wed Sep 23, 2009 11:41 am
by 15653372
Hi,

Yes that is what i get too, when the window is too small for the legend rect it will give the error. The project im working on is a dashboard where multiple small windows can be placed and can contain a chart. So if someone resize one of these windows too small it will give this error.

Re: Legend resize

Posted: Wed Sep 23, 2009 1:55 pm
by yeray
Hi SPS,

We've just fixed a bug that could solve your problem in NET v2009 but to ensure that to you it would be helpful if you could send us a simple code snipped we can run as-is here to reproduce the problem here.

For example, the fixed problem was reproducible with the following:

Code: Select all

tChart1.Aspect.View3D = false;

for (int i = 0; i < 40; i++)
{
    tChart1.Series.Add(new Steema.TeeChart.WPF.Styles.Line());
    tChart1[i].FillSampleValues();
    tChart1[i].Title = "this is a series with a very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long name";
}

Re: Legend resize

Posted: Wed Sep 23, 2009 2:59 pm
by 15653372
Here is a sample project that reproduce the error when making the window as small as possible.

Re: Legend resize

Posted: Wed Sep 23, 2009 3:11 pm
by yeray
Hi SPS,

Are you sure that the project you've attached is reproducing the legend problem? Here it gives me another "Height must be non-negative." error:
System.ArgumentException was unhandled
Message="Height must be non-negative."
Source="WindowsBase"
StackTrace:
at System.Windows.Rect.set_Height(Double value)
at Steema.TeeChart.WPF.Chart.CalcWallsRect(Rect& r)
at Steema.TeeChart.WPF.Chart.InternalDraw(DrawingContext g, Boolean noTools)
at Steema.TeeChart.WPF.Chart.InternalDraw(DrawingContext g)
at Steema.TeeChart.WPF.TChart.Draw(DrawingContext g)
at Steema.TeeChart.WPF.TChart.OnRender(DrawingContext drawingContext)

Re: Legend resize

Posted: Wed Sep 23, 2009 3:12 pm
by 15653372
Hi yes, because when removing the legend it works ok

Re: Legend resize

Posted: Thu Sep 24, 2009 9:20 am
by yeray
Hi SPS,

Yes, I see in your error message that the legend rectangle is what is crashing for you. But here I can see the walls rectangle crashing in one computer (error posted above) and the title rectangle in another:
System.ArgumentException was unhandled
Message="Height must be non-negative."
Source="WindowsBase"
StackTrace:
at System.Windows.Rect.set_Height(Double value)
at Steema.TeeChart.WPF.Title.Draw(Graphics3D g, Rect& rect)
at Steema.TeeChart.WPF.Title.DoDraw(Graphics3D g, Rect& rect, Boolean CustomOnly, String Entity)
at Steema.TeeChart.WPF.Chart.DrawTitleFoot(Rect& rect, Boolean CustomOnly)
at Steema.TeeChart.WPF.Chart.DrawTitlesAndLegend(DrawingContext g, Rect& tmp, Boolean BeforeSeries)
at Steema.TeeChart.WPF.Chart.InternalDraw(DrawingContext g, Boolean noTools)
at Steema.TeeChart.WPF.Chart.InternalDraw(DrawingContext g)
at Steema.TeeChart.WPF.TChart.Draw(DrawingContext g)
at Steema.TeeChart.WPF.TChart.OnRender(DrawingContext drawingContext)
Anyway I've added this to be revised for next releases (TW16014439).

In the meanwhile I can only think on removing the legend at OnResize event when the window height is too small.

Re: Legend resize

Posted: Thu Sep 24, 2009 12:46 pm
by 15653372
Ok, Thanks

Re: Legend resize

Posted: Thu Sep 24, 2009 1:08 pm
by 15653372
Is there a way to get the legend height when its visibilty state is set to false ?

Re: Legend resize

Posted: Thu Sep 24, 2009 2:00 pm
by yeray
Hi SPS,

I'm afraid that's not possible. The legend rectangle information isn't available until it is being drawn.
So you should save the heigh into a variable before hiding it.