Profile Picture

PlotArea correct value

Posted By Alexandr S. 12 Years Ago
Author
Message
Alexandr S.
Posted 12 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 23, Visits: 6
Hi again I need to know valid value of PlotArea property before the first draw of the chart. (I want to place legends according the size of the plot area), but help says: "This property contains valid value after the document layout has been been performed".
Is there any way to force chart control calculate this value when I need it?

For now I just setup a timer and read PlotArea after the chartcontrol is created, but this is ugly. Please help!

Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Alexandr,

You can explicitly force the contorl to recalculate using the following code:

nChartControl1.Document.Calculate();
nChartControl1.Document.RecalcLayout(nChartControl1.View.Context);

Then you can read all layout related properties.

Hope this helps - let us know if you meet any problems.



Best Regards,
Nevron Support Team



Alexandr S.
Posted 12 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 23, Visits: 6
Unforunatelly it doesnt help. After the call of this code PlotArea is filled with some initial values (height and width = 150). It is better then zero but this values are not final. So if Ill place legends using these values the position would be wrong.

May be you can suggest another way to solve my problem? I just want to place legend panel within the plot area, for example at the top by Y and center by X, see the attached pic.

Attachments
p1.png (57 views, 19.00 KB)
Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Alexanrd,

You can place the legend as a child panel of the chart and modify it's location and content alignemnt - for example:

   nChartControl1.Panels.Clear();

   NCartesianChart chart = new NCartesianChart();
   chart.BoundsMode = BoundsMode.Stretch;
   NBarSeries bar = new NBarSeries();
   bar.Values.Add(10);
   bar.Values.Add(20);
   bar.Values.Add(30);
   
   chart.Series.Add(bar);

   nChartControl1.Panels.Add(chart);

   NLegend legend = new NLegend();

   legend.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(5));
   legend.ContentAlignment = ContentAlignment.TopCenter;

   chart.PositionChildPanelsInContentBounds = true;
   chart.ChildPanels.Add(legend);

   chart.DisplayOnLegend = legend;

This should do the job...



Best Regards,
Nevron Support Team



Alexandr S.
Posted 12 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 23, Visits: 6
We are close I tried your code, please see the attached pic. The left panel is nevron settings for legend from the upper chart sample.
The bottom chart sample is rendered with settings:

legend.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(5));
legend.ContentAlignment = ContentAlignment.BottomLeft;

Both charts has the problem : in the first half of the legend is out of chart area, in the second legend is not centred well. It is slightly shifted to the left.

I dont know the legend pabel size, so I have to use location values like 50% or 100%. How should I tune legend to make it be placed in correct place?

Attachments
p1.png (58 views, 99.00 KB)
Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Alexandr,
Did you make the legend a child panel of the chart? Also don't forget to set:

chart.PositionChildPanelsInContentBounds = true;

This tells the control to use the chart plot bounds instead of the chart content bounds (which will result in a slight shift to the left). Also the legend content alignment should be BottomCenter not BottomLeft. Let us know if you meet any problems...



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic