Update Chart after property change (updating majorstep value)

Thread is closed for posting
2 posts, 0 answers
  1. Trevor
    Trevor avatar
    1 posts
    Member since:
    Jan 2013

    Posted 20 Jan 2014 Link to this post

    I have a RadChart on my page.  Here is the XAML.

    <telerikChart:RadCartesianChart x:Name="myChart" >
            <telerikChart:LinearAxis LineThickness="2" />
            <telerikChart:CartesianChartGrid MajorLinesVisibility="X" MajorXLinesRenderMode="All"/>
            ItemsSource="{Binding TimeReportChartData}"
            Stroke="{StaticResource AppAccentBrush}"
            Fill="{StaticResource AppForegroundBrush}"

    After page initialization I want to check the data and change the majorstep value so that the data is formatted in the appropriate way.

    Here is my code to do that:

    if (App.ViewModel.icReport.Count > 1) {
         var axis = myChart.VerticalAxis as LinearAxis;
          if (axis != null) axis.MajorStep = 10;
    } else {
         var axis = myChart.VerticalAxis as LinearAxis;
         if (axis != null) axis.MajorStep = 2;

    If you back out of the page and reopen it with the same data, then yes, it shows the correct major step, but I would like it to show the correct data immediately.  I am sure this is a very minor thing to fix, but please help.
  2. Rosy Topchiyska
    Rosy Topchiyska avatar
    586 posts

    Posted 21 Jan 2014 Link to this post

    Hello Trevor,

    Thank you for contacting us.

    It seems that at the first moment you set the MojorStep property, your icReport collection is empty. Since you set it only once, the ticks are not updated when the collection is changed afterwards. When you reload the page, the collection already has some items in it and the MajorStep gets the other value.

    You have to update the MajorStep property every time your icReport collection is changed. One way to do this is to set binding to the icReport and via a value converter to get the desired step. Alternatively, you can add a property to your view model that you can bind to and update this property every time the collection is changed. I have attached a sample project that realizes the second suggestion.

    I hope this was useful. Please, let us know if you have further questions.

    Rositsa Topchiyska
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Back to Top