Binding ItemsSource to LineSeries

3 posts, 1 answers
  1. kl
    kl avatar
    3 posts
    Member since:
    Aug 2008

    Posted 05 Nov 2012 Link to this post

    I'm having difficulty to display the data on the chart where the data are changed dynamically.
    The graph would not populate the data according to the changes made.
    Below is the snippet of the code, kindly guide if i did anything wrong.

    p/s: The GetData will get the changes of data to be plot on the graph

    XAML:
    <chartView:LineSeries Stroke="Red" StrokeThickness="2" ItemsSource="{Binding ListValue}" ValueBinding="Value" CategoryBinding="Category">

    ViewModel.cs
    private List<SampleClass> tempList;
    public List<SampleClass> ListValue
    {
         :
         :
    }
    public void GetData(string tempValue)
    {
           SampleClass item = new SampleClass ();
           item.Value= tempValue;
           item.Category = m_counter++;
           tempList.Add(item);
     
           ListValue= tempList;
    }
  2. Answer
    Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 08 Nov 2012 Link to this post

    Hi,

    The problem is that the List<> class does not notify the chart that its data has changed. Changing the ItemsSource from List<> to ObservableCollection<> should solve the problem.
     
    Regards,
    Petar Kirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. kl
    kl avatar
    3 posts
    Member since:
    Aug 2008

    Posted 11 Nov 2012 Link to this post

    thank you. it works fine now.
Back to Top