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

Rad cartesian chart doesn't update automaticaly

6 Answers 389 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Popo
Top achievements
Rank 1
Popo asked on 21 Nov 2013, 03:47 PM
I have a rad cartesian chart i need it to update each time the user  choose an item in a datagrid.

This is the code behind:
private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            chartdatas.Clear();
            chartdatas2.Clear();
         
            VariablesDescription temp = ((DataGrid)sender).SelectedItem as VariablesDescription;
            if (temp != null)
            {
                UpdateVariablesLabels(temp.Name);
 
                if (temp != null)
                {
                    string name = temp.Name;
                  foreach (ModelVariable model in this.data.ModelVariables)
                    {
                        string comp = model.variableName;
                        string[] word = comp.Split('.');
                        string ToCompar = word[word.Length - 1];
                        if (ToCompar == name)
                        {
 
                            for (int i = 0; i < model.modalities.Count; ++i)
                            {
                                Modality modality = this.data.ModelVariables[2].modalities[i];
                                CharDataclass cd = new CharDataclass();
                                CharDataclass cd2 = new CharDataclass();
                                cd.XValue = modality.Percent_target;
                                cd.YValue = i;
                                cd2.YValue = i;
                                chartdatas.Add(cd);
                                cd2.XValue = modality.Percent_in_universe;
                                chartdatas2.Add(cd2);
                            }
 
                            graph1.Series[0].ItemsSource = chartdatas;
                            graph2.DataContext = chartdatas2;
 
                        }
                    }
 
                }
            }
        }


This is the xaml:
<telerik:RadCartesianChart Height="240" HorizontalAlignment="Left" Margin="448,408,0,0" Name="graph1" VerticalAlignment="Top" Width="486" Zoom="10,1">
                    <telerik:RadCartesianChart.Behaviors>
                        <telerik:ChartPanAndZoomBehavior PanMode="Horizontal" ZoomMode="Horizontal" />
                    </telerik:RadCartesianChart.Behaviors>
                    <telerik:RadCartesianChart.HorizontalAxis>
                        <telerik:CategoricalAxis />
                    </telerik:RadCartesianChart.HorizontalAxis>
                    <telerik:RadCartesianChart.VerticalAxis>
                        <telerik:LinearAxis HorizontalLocation="Left" Name="Axis1" />
                    </telerik:RadCartesianChart.VerticalAxis>
                    <telerik:BarSeries CategoryBinding="YValue" ItemsSource="{Binding}" ValueBinding="XValue">
                        <telerik:BarSeries.PointTemplate>
                            <DataTemplate>
                                <Rectangle Fill="Black" />
                            </DataTemplate>
                        </telerik:BarSeries.PointTemplate>
                    </telerik:BarSeries>
                    <telerik:LineSeries CategoryBinding="YValue" ItemsSource="{Binding}" Name="graph2" ValueBinding="XValue">
                        <telerik:LineSeries.PointTemplate>
                            <DataTemplate>
                                <Ellipse Fill="Red" Height="7" Width="7" />
                            </DataTemplate>
                        </telerik:LineSeries.PointTemplate>
                        <telerik:LineSeries.VerticalAxis>
                            <telerik:LinearAxis HorizontalLocation="Right" Name="Axis2" />
                        </telerik:LineSeries.VerticalAxis>
                    </telerik:LineSeries>
                </telerik:RadCartesianChart>

Using this code the chart display the first item, when i choose another one the chart doesn't update with the new datas.

Many thanks :)


6 Answers, 1 is accepted

Sort by
0
Popo
Top achievements
Rank 1
answered on 26 Nov 2013, 09:26 AM
No help for this issue?
0
Pavel R. Pavlov
Telerik team
answered on 26 Nov 2013, 01:06 PM
Hi,

Thank you for providing us with detailed information about your scenario. As far as I understand you need to change the visualized data in the RadChartView control at runtime. Let me try to explain the steps that you need to take in order to achieve your requirement.

In your custom case, in order to use the LineSeries and/or the BarSeries you need to define three properties. They are the following:
  • ItemsSource - it holds the collection of data items
  • CategoryBinding - the property where the category is hold (for the CategoricalAxis)
  • ValueBinding - the property where the value is hold (for the LinearAxis)
In order to change the data that is visualize you can change the ItemsSource of both series. You need to keep in mind that the new collection should hold proper data items. Meaning that each item should expose properties holding the values for both axis. In your particular case I am not sure what is the implementation of the ChartDataClass, this is why I cannot be sure about the exact reason for the reported behavior.

Another, way is to change some of the other 2 properties. For example you can change ValueBinding using the PropertyNameDataPointBinding class. You need to have in mind that by following this approach you need to extend the definition of the item holding your data. You need to specify the values for both layouts (the one before the change and after the change).

For your convenience I prepared a sample demonstration project what shows both approaches. Please take a look at it and let us know if you need any further assistance.

Regards,
Pavel R. Pavlov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Popo
Top achievements
Rank 1
answered on 26 Nov 2013, 01:58 PM
Thank you for your answer :) 

This is the code of the chartdataclass, 
public class CharDataclass
  {
      public double XValue { get; set; }
      public double YValue { get; set; }
 
      public CharDataclass() { }
  }

It's simply a container for the points i want to display. 
0
Pavel R. Pavlov
Telerik team
answered on 29 Nov 2013, 11:53 AM
Hi Popo,

Did you download the attached project in my previous post. It demonstrates how you can achieve your requirement. Also the class representing a single point is similar to yours.

Please take a look at the solution and let me know if you have any questions.

Regards,
Pavel R. Pavlov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Popo
Top achievements
Rank 1
answered on 03 Dec 2013, 11:13 AM
I still can't implement your solution in my code. Actually the issue is that in your code you have a certain amount of data's but in mine I don't know how many data's will I have to display in the chart.

thank you for your help :)
0
Yavor
Telerik team
answered on 04 Dec 2013, 09:56 AM
Hi Popo,

In order for the RadChartView to display data in needs some configuration. In particular it needs to know where to get its data from (the ItemsSource property). So in the most basic scenario you just set the ItemsSource property of the series to a list of integers, doubles, etc. Here is some code:

var series = this.chart.Series[0] as PointTemplateSeries;
series.ItemsSource = new int[] { 1, 2, 3, 4, 5 };

When your data is a collection of objects that hold valuable data in a member you need to configure the chart. It doesn't matter how many items you have in your collection. You can have 1 item, or you can have thousands or millions of items. In that case check the reply of Pavel.

More information on data binding can be found in our online help topic here.

Regards,
Yavor
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
ChartView
Asked by
Popo
Top achievements
Rank 1
Answers by
Popo
Top achievements
Rank 1
Pavel R. Pavlov
Telerik team
Yavor
Telerik team
Share this question
or