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

Update Chart after property change (updating majorstep value)

1 Answer 108 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.
Trevor
Top achievements
Rank 1
Trevor asked on 20 Jan 2014, 04:21 PM
I have a RadChart on my page.  Here is the XAML.

<telerikChart:RadCartesianChart x:Name="myChart" >
    <telerikChart:RadCartesianChart.HorizontalAxis>
        <telerikChart:CategoricalAxis
            GapLength="0.5"
            LabelInterval="1"
            LabelOffset="1"
            PlotMode="OnTicks"
            TickThickness="8"
            ZIndex="1"/>
    </telerikChart:RadCartesianChart.HorizontalAxis>
    <telerikChart:RadCartesianChart.VerticalAxis>
        <telerikChart:LinearAxis LineThickness="2" />
    </telerikChart:RadCartesianChart.VerticalAxis>
    <telerikChart:RadCartesianChart.Grid>
        <telerikChart:CartesianChartGrid MajorLinesVisibility="X" MajorXLinesRenderMode="All"/>
    </telerikChart:RadCartesianChart.Grid>
    <telerikChart:AreaSeries
        CategoryBinding="Header"
        ValueBinding="Time"
        ItemsSource="{Binding TimeReportChartData}"
        Stroke="{StaticResource AppAccentBrush}"
        Fill="{StaticResource AppForegroundBrush}"
        ClipToPlotArea="False">
    </telerikChart:AreaSeries>
</telerikChart:RadCartesianChart>


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.

1 Answer, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 21 Jan 2014, 12:04 PM
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.

Regards,
Rositsa Topchiyska
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Chart
Asked by
Trevor
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Share this question
or