Group: Forum Members
Last Active: 4 Years Ago
Posts: 5,
Visits: 17
|
I have been going around in circles trying to size charts within panels using WPF !& nbsp ; There is a general lack of proper examples and documentation . I have a chart control in a window & lt ; Wpf : NChartControl x : Name =" nChartControl1 " Margin =" 5 , 0 , 0 , 5 " Width =" 800 " Height =" 500 " HorizontalAlignment =" Left " VerticalAlignment =" Top "/& gt ; I have a CartesianChart and a legend within that .& nbsp ; So , for example , how do I locate the legend on the right hand side half way up centered around the vertical mid point of the control .& nbsp ; There should be fixed gap between the right hand edge of the legend and the right hand edge of the chartcontrol .& nbsp ; The chart should be 50 % of the height of the chart control and 80 % of the width , again located around midpoint of the height but a fixed distance from the lefthand edge of the control ?& nbsp ; Thanks Rich
|
Group: Forum Members
Last Active: Last Month
Posts: 3,055,
Visits: 4,055
|
Hi Richard , The following code configures the layout so that both the chart and the legend are centered vertically and at fixed offset from the sides of the control : NChart chart = nChartControl1 . Charts [ 0 ]; NLegend legend = nChartControl1 . Legends [ 0 ]; // at fixed distance from the left side ( 20pt ), but centered relative to height chart . ContentAlignment = ContentAlignment . MiddleRight ; chart . Location = new NPointL ( new NLength ( 20 ), new NLength ( 50 , NRelativeUnit . ParentPercentage )); & nbsp ;& nbsp ;& nbsp ;& nbsp ;// 50 % of the height of the chart control and 80 & nbsp ;& nbsp ;& nbsp ;& nbsp ; chart . Size = new NSizeL ( new NLength ( 80 , NRelativeUnit . ParentPercentage ), new NLength ( 50 , NRelativeUnit . ParentPercentage )); & nbsp ;& nbsp ;& nbsp ;& nbsp ;// at fixed distance from the right side ( 20pt ) centered relative to height & nbsp ;& nbsp ;& nbsp ;& nbsp ; legend . ContentAlignment = ContentAlignment . MiddleLeft ; & nbsp ;& nbsp ;& nbsp ;& nbsp ; legend . Location = new NPointL ( new NLength ( 100 , NRelativeUnit . ParentPercentage ), new NLength ( 50 , NRelativeUnit . ParentPercentage )); & nbsp ;& nbsp ;& nbsp ;& nbsp ; legend . Margins = new NMarginsL ( new NLength ( 0 ), new NLength ( 0 ), new NLength ( 20 ), new NLength ( 0 )); We hope this helps - let us know if you meet any problems or have any questions .
Best Regards, Nevron Support Team
|
Group: Forum Members
Last Active: 4 Years Ago
Posts: 5,
Visits: 17
|
Thanks .& nbsp ; So a couple of questions . If you want to align to the left edge do you use contentalignment = middleright ? Also , I have this code& nbsp ; nChartControl1 . Charts . Clear () & nbsp ;& nbsp ; nChartControl1 . Legends . Clear () & nbsp ;& nbsp ; Dim chart As NCartesianChart = New NCartesianChart & nbsp ;& nbsp ; Dim legend As NLegend = New NLegend & nbsp ;& nbsp ; nChartControl1 . Charts . Add ( chart ) & nbsp ;& nbsp ; nChartControl1 . Panels . Add ( legend ) & nbsp ;& nbsp ; chart . DisplayOnLegend = legend & nbsp ; & nbsp ; legend . ContentAlignment = System . Drawing . ContentAlignment . MiddleLeft & nbsp ;& nbsp ; legend . Location = New NPointL ( New NLength ( 100 , NRelativeUnit . ParentPercentage ), New NLength ( 50 , NRelativeUnit . ParentPercentage )) & nbsp ;& nbsp ; legend . Margins = New NMarginsL ( New NLength ( 0 ), New NLength ( 0 ), New NLength ( 10 ), New NLength ( 0 )) & nbsp ; & nbsp ; chart . ContentAlignment = System . Drawing . ContentAlignment . MiddleRight & nbsp ;& nbsp ; chart . Size = New NSizeL ( New NLength ( 100 , NRelativeUnit . ParentPercentage ), New NLength ( 50 , NRelativeUnit . ParentPercentage )) & nbsp ;& nbsp ; chart . Location = New NPointL ( New NLength ( 0 ), New NLength ( 50 , NRelativeUnit . ParentPercentage )) The legend is where I expect it but the chart should be the full width of the window starting from the left but it isn ' t .& nbsp ; Why is that ? 60% of original size (was 842x562) - Click to enlarge  Thanks Rich
|
Group: Forum Members
Last Active: 4 Years Ago
Posts: 5,
Visits: 17
|
If I reduce the size of the chart in the x direction then it gradually moves it into the correct position. There is clearly some auto sizing and positioning going on. Can that be disabled? Or maybe it is an auto aspect ratio fix. Not sure. I hope you can help. Rich
|
Group: Forum Members
Last Active: 4 Years Ago
Posts: 5,
Visits: 17
|
If I reduce the size of the chart it moves to the right place. Is there some auto sizing or aspect ratio control that is still active? Or is it WPF related? thanks Rich
|
Group: Forum Members
Last Active: Last Month
Posts: 3,055,
Visits: 4,055
|
Hi Rich , Yes , it ' s the aspect control that you need to turn off - just set : chart . BoundsMode = BoundsMode . Stretch ; and this should fix the problem . The following WinForm example shows how to control the aspect / stretch : Panels \ Chart \ Aspect \ Aspect 2D . Regarding middle right - yes , that is the correct setting - it means right relative to the specified Location & nbsp ; check out the following topic : http://helpdotnetvision.nevron.com/#UsersGuide_Layout_Content_Panels.html It shows how ContentAlignment aligns the panel relative to the location . We hope this helps – let us know if you meet any problems or have any questions .
Best Regards, Nevron Support Team
|