Author
|
Message
|
Tal Harari
|
|
Group: Forum Members
Last Active: 9 Years Ago
Posts: 19,
Visits: 2
|
hi,
I'm trying to set custom axis min\max values, that i calculate based on the current min\max values of my cartesian chart.
I've come to realize that the scale's min\max values do not update, only until after the chart is painted, so I created a PaintCallback class that I use to recalculate the min\max values' and use them by creating a new RangeView for the axis.
The problem is that when I set the new min\max values to the chart in the paint callback class (doesn't matter if I do it on Before\After paint) the axis range doesn't update, but only after about a second or so.
here is a general example of what i'm doing (cant post the real code here):
class MyForm : Form { public MyForm() { InitializeComponents();
NCartesianChart chart = new NCartesianChart();
// ... // Add the chart to the NChartControl // ... // Create series for chart // ... // bind chart to datatable // ...
chart.PaintCallback = new MyPaintCallback(); }
// ... // Other Methods // ... }
class MyPaintCallback : NPaintCallback { public override void OnBeforePaint(NPanel panel, NPanelPaintEventArgs eventArgs) { double min = chart.Axis(StandardAxis.PrimaryY).SeriesRange.Begin - 20; double max = chart.Axis(StandardAxis.PrimaryY).SeriesRange.End + 50; chart.Axis(StandardAxis.PrimaryY).View = new NRangeAxisView(new NRange1DD(min, max), true, true); } }
Can i make the axis refresh its range after i change it? Or perhaps i need change the min\max values in some other way?
|
|
|
Nevron Support
|
|
Group: Forum Members
Last Active: Last Week
Posts: 3,054,
Visits: 4,009
|
Hi Tal, If you want to inflate the axis range in logical scale you can use: NLinearScaleConfigurator scale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator; scale.ViewRangeInflateMode = ScaleViewRangeInflateMode.Logical; scale.InflateViewRangeBegin = true; scale.InflateViewRangeEnd = true; scale.LogicalInflate = new NRange1DD(20, 20); Otherwise you can force the chart to recalculate: nChartControl1.Document.Calculate(); nChartControl1.Document.RecalcLayout(nChartControl1.View.Context); then you can access the axis series range and not have to bother with the paint callbacks.
Best Regards, Nevron Support Team
|
|
|
Tal Harari
|
|
Group: Forum Members
Last Active: 9 Years Ago
Posts: 19,
Visits: 2
|
The code I've written above is just an example. What I'm really doing is having multiple cartesian charts on my ChartControl and setting their min\max axis values according to the other charts in the control (meaning - I want all my charts to have the same min\max values, so i can compare the data easily). So logical inflation is not the answer in my case.
Is there another way to refresh the chart without using the ChartControl itself?
|
|
|
Nevron Support
|
|
Group: Forum Members
Last Active: Last Week
Posts: 3,054,
Visits: 4,009
|
HI Tal, In this case you can use master/slave axes - this will synchronize the ranges of the axes that have this relashionship - for example: chart1.Axis( StandardAxis.PrimaryX).Slaves.Add(chart2.Axis(StandardAxis.PrimaryX)):
will synchronize primaryX of the second chart with the range of the first one...
Best Regards, Nevron Support Team
|
|
|
Tal Harari
|
|
Group: Forum Members
Last Active: 9 Years Ago
Posts: 19,
Visits: 2
|
Hi,
I've just tried the master-slave option with my PrimaryY Axis, but it didn't change anything. The axes still have diffrent max values. What was it supposed to synchronize exactly? Am I doing something wrong?
|
|
|
Nevron Support
|
|
Group: Forum Members
Last Active: Last Week
Posts: 3,054,
Visits: 4,009
|
Hi Tal, Just tested with the following code and it was working OK: NChart chart1 = new NCartesianChart(); NBarSeries bar1 = new NBarSeries();bar1.Values.Add(10); bar1.Values.Add(20); bar1.Values.Add(30); chart1.Series.Add(bar1); chart1.Location = new NPointL(new NLength(10, NRelativeUnit.ParentPercentage), new NLength(10, NRelativeUnit.ParentPercentage)); chart1.Size = new NSizeL(new NLength(40, NRelativeUnit.ParentPercentage), new NLength(40, NRelativeUnit.ParentPercentage));NChart chart2 = new NCartesianChart(); NBarSeries bar2 = new NBarSeries(); bar2.Values.Add(10); bar2.Values.Add(20); bar2.Values.Add(70); chart2.Series.Add(bar2);chart2.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(50, NRelativeUnit.ParentPercentage)); chart2.Size = new NSizeL(new NLength(40, NRelativeUnit.ParentPercentage), new NLength(40, NRelativeUnit.ParentPercentage)); nChartControl1.Panels.Clear();nChartControl1.Panels.Add(chart1); nChartControl1.Panels.Add(chart2); chart2.Axis( StandardAxis.PrimaryY).Slaves.Add(chart1.Axis(StandardAxis.PrimaryY));
Best Regards, Nevron Support Team
|
|
|
Nevron Support
|
|
Group: Forum Members
Last Active: Last Week
Posts: 3,054,
Visits: 4,009
|
Hi Tal,
Regarding a previous question - you can force the chart to recalculate: nChartControl1.Document.Calculate(); nChartControl1.Document.RecalcLayout(nChartControl1.View.Context);
Then all axes view range will be finalized: someChart.Axis( StandardAxis.PrimaryY).ViewRange; and you can gather these and apply a range axis view. This will also fix the problem.
Best Regards, Nevron Support Team
|
|
|
Tal Harari
|
|
Group: Forum Members
Last Active: 9 Years Ago
Posts: 19,
Visits: 2
|
Eventually i came back to my old solution with the PaintCallbacks and forced the chart to recalculate by using the parameters like this:
(panel as NCartesianChart).RecalcLayout(e.Context);
and it solved my problem.
Anyway, thank you very much for all your help.
|
|
|