This is a migrated thread and some comments may be shown as answers.

How to define the Maximum/Minimum in code?

3 Answers 333 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Eitan
Top achievements
Rank 1
Eitan asked on 25 Jun 2012, 06:58 PM
Hi,

I have this XAML that defines the Maximum & Minimum.

I need to define these parameters in my C# application.

Thanks,
Eitan Barazani

<
chart:RadCartesianChart.VerticalAxis>
    <chart:LinearAxis Maximum="250" Minimum="150" /> </chart:RadCartesianChart.VerticalAxis>

3 Answers, 1 is accepted

Sort by
0
Lancelot
Top achievements
Rank 1
answered on 25 Jun 2012, 07:19 PM
Hi Eitan,

You'll need to define the vertical axis in your page class. You can do that simply by adding an x:Name="exampleVerticalAxis" to the xaml.  Then in your code behind, set the parameters through the instantiated axis name.   Like this:

exampleVerticalAxis.Maximum = 250;
exampleVerticalAxis.Minimum = 150;

You can do this in the contructor or in a Loaded event. In your case I would remove the explicit values from the xaml and replace it with only the x:Name value 


Good Luck,
Lancelot
0
Eitan
Top achievements
Rank 1
answered on 25 Jun 2012, 08:43 PM
Hi,

I defined it in the Loaded event like you said.

Minimum is always set to 0. Maximum is set to the maximum of the series (your component calculates it automatically).

If I set Minimum/Maximum in XAML then Minimum/Maximum are correct on the graph.

Can it be that you have a bug here? or maybe I declare verticalAxis wrong?

Thanks,
Eitan

============================================

Doesn't work for Minimum or Maximum
<chart:RadCartesianChart.VerticalAxis>
    <chart:LinearAxis x:Name="verticalAxis"/>
</chart:RadCartesianChart.VerticalAxis>

-----------------------------------------------
verticalAxis = new LinearAxis(); 
verticalAxis.Minimum = 100;
verticalAxis.Maximum = 200;

================================================
0
Victor
Telerik team
answered on 26 Jun 2012, 09:56 AM
Hello Eitan,

Thanks for the question.
This is a bug indeed however it is a bug of the Silverlight framework itself. Since the chart axes are declared in RadChart's HorizontalAxis and VerticalAxis properties, Silverlight fails to assign them at run-time to the auto-generated verticalAxis field because the FindName method returns null. Silverlight has a broken notion of the visual and logical trees (as defined in WPF) and for unknown reasons combines them in one tree resulting in this behavior.

In order to obtain a reference to your vertical axis you need to set x:Name="chart" on your chart (for example) and then do this in C# after the InitializeComponent() method of your page has finished executing:

(this.chart.VerticalAxis as LinearAxis).Maximum = 200;
The same is true for the chart series as described here.

Please write again if you have other questions.

All the best,
Victor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Chart
Asked by
Eitan
Top achievements
Rank 1
Answers by
Lancelot
Top achievements
Rank 1
Eitan
Top achievements
Rank 1
Victor
Telerik team
Share this question
or