Rad cartesian chart doesn't update automaticaly

7 posts, 0 answers
  1. Popo
    Popo avatar
    4 posts
    Member since:
    Nov 2013

    Posted 21 Nov 2013 Link to this post

    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 :)


  2. Popo
    Popo avatar
    4 posts
    Member since:
    Nov 2013

    Posted 26 Nov 2013 Link to this post

    No help for this issue?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 26 Nov 2013 Link to this post

    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 >>
  5. Popo
    Popo avatar
    4 posts
    Member since:
    Nov 2013

    Posted 26 Nov 2013 Link to this post

    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. 
  6. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 29 Nov 2013 Link to this post

    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 >>
  7. Popo
    Popo avatar
    4 posts
    Member since:
    Nov 2013

    Posted 03 Dec 2013 Link to this post

    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 :)
  8. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 04 Dec 2013 Link to this post

    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 >>
Back to Top
UI for WPF is Visual Studio 2017 Ready