Program editing data points in Visual "Data Editing" sample

Can you please help me, how to work with data points manually? I need to change existing and add new data points from code (from MainWindow class) by keeping visual drag&drop interaction of course. Adding new instance of SalesAnalysisViewModel class to MainWindow class and adding new points to it has no result.

2 Replies

?? ???? August 3, 2018 10:58 AM UTC

I am talking about regular demo sample from Essential Studio (2018, Vol 2), called "Data Editing", I have attached it.
So... can anybody help me?

Attachment: Data_Editing_40bff365.zip


MK Muneesh Kumar G Syncfusion Team August 6, 2018 11:32 AM UTC

Hi Ivan, 
 
We have analyzed your requirement and you can achieve this by manipulating the ItemsSource property in series and do the required action as per the below code snippet.  
 
Code Snippet 
 
Add:  
 
 
        private void AddDataButton_Click(object sender, RoutedEventArgs e) 
        { 
            var model = new Model() { XValue = counter * 10, YValue = random.Next(100, 150) }; 
            var dataSource = (this.LineSeries1.ItemsSource as ObservableCollection<Model>); 
 
            dataSource.Add(model); 
 
            counter++; 
        } 
                     
 
 
Replace:  
 
 
        private void ChangeDataButton_Click(object sender, RoutedEventArgs e) 
        { 
            var model = new Model() { XValue = 10, YValue = random.Next(100, 150) }; 
            var dataSource = (this.LineSeries1.ItemsSource as ObservableCollection<Model>); 
 
            dataSource[0] = model; 
        }                     
 
 
Update :  
 
To update a certain value in the model. Implement property change for the model and enable the ListenPropertyChange property of the series and then replace the value at the required index. 
 
XAML 
 
 
        <chart:SfChart Margin="20"> 
        … 
 
            <chart:LineSeries XBindingPath="XValue"  
                              YBindingPath="YValue"  
                              ItemsSource="{Binding Data}" 
                              x:Name="LineSeries1" 
                              ListenPropertyChange="True"/> 
 
 
        </chart:SfChart> 
 
 
C# 
 
 
    public class Model : INotifyPropertyChanged 
    { 
        public event PropertyChangedEventHandler PropertyChanged; 
 
        private double yValue { get; set; } 
 
        … 
 
        public double YValue 
        { 
            get 
            { 
                return yValue;  
            } 
 
            set 
            { 
                yValue = value; 
                OnPropertyChanged("YValue"); 
            } 
        } 
 
        private void OnPropertyChanged(string propertyName) 
        { 
            PropertyChangedEventHandler handler = PropertyChanged; 
            if(handler != null) 
            { 
                handler(this, new PropertyChangedEventArgs(propertyName)); 
            } 
        } 
    } 
 
 
 
        private void ChangeValueButton_Click(object sender, RoutedEventArgs e) 
        { 
            var dataSource = (this.LineSeries1.ItemsSource as ObservableCollection<Model>); 
            dataSource[2].YValue = random.Next(100,150); 
        } 
 
 
We have prepared a sample based on this. Please find it from the link below. 
 
 
Hope this helps.  
 
Regards,
Muneesh Kumar G. 
 


Loader.
Up arrow icon