How to define the Maximum/Minimum in code?

Thread is closed for posting
4 posts, 0 answers
  1. Eitan
    Eitan avatar
    26 posts
    Member since:
    Jun 2012

    Posted 25 Jun 2012 Link to this post


    I have this XAML that defines the Maximum & Minimum.

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

    Eitan Barazani

        <chart:LinearAxis Maximum="250" Minimum="150" /> </chart:RadCartesianChart.VerticalAxis>
  2. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 25 Jun 2012 Link to this post

    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,
  3. Eitan
    Eitan avatar
    26 posts
    Member since:
    Jun 2012

    Posted 25 Jun 2012 Link to this post


    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?



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

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

  4. Victor
    Victor avatar
    1358 posts

    Posted 26 Jun 2012 Link to this post

    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,
    the Telerik team

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

Back to Top