2016-08-02 2 views
1

ボタンをクリックするたびにAreaSeriesを更新しようとしているWPFToolkitベースのグラフを作成しています。 データクラスにINotifyPropertyChangedを実装しました。私は、ソースオブジェクトIDのデータをリロードする際、チャート(ターゲットオブジェクト)WPFToolkit AreaSeriesグラフの更新方法ボタンクリック

に更新コードは以下のようになるないが:

public partial class MainWindow : Window 
{ 

    static List<Ready4LOS> Ready4LOS = new List<Data.Ready4LOS>(); 





    public MainWindow() 
    { 
     InitializeComponent(); 

     chart1.DataContext = Ready4LOS; 
     InitChart(); 
     LoadData(); 
    } 

    private void LoadData() 
    { 
     var path = @"zxzxzxz.log"; 
     Ready4LOS.Clear(); 
     List<APISTATDataModel> daa = APISTATDataModel.GetFromFile(path, new string[] { "|" }, "Ready4TOS"); 

     List<APISTATDataModel> lastn = daa.GetRange(daa.Count - 10, 10); 

     foreach (APISTATDataModel d in lastn) 
     { 
      Ready4LOS.Add(new Ready4LOS() { Case = d.Current_Count, Time = d.Current_Time }); 

     } 

    } 

    private void InitChart() 
    { 
     System.Windows.Data.Binding indi = new System.Windows.Data.Binding("Case"); 
     System.Windows.Data.Binding dep = new System.Windows.Data.Binding("Time"); 
     dep.Mode = System.Windows.Data.BindingMode.OneWay; 
     indi.Mode = System.Windows.Data.BindingMode.OneWay; 
     AreaSeries ares = new AreaSeries(); 
     ares.ItemsSource = Ready4LOS; 
     ares.IndependentValueBinding = dep; 
     ares.DependentValueBinding = indi; 
     ares.Title = "Ready4LOS"; 

     DateTimeAxis dta = new DateTimeAxis(); 
     dta.Interval = 10; 
     dta.IntervalType = DateTimeIntervalType.Minutes; 
     dta.Title = "Time"; 
     dta.Orientation = AxisOrientation.X; 
    // dta.Minimum = DateTime.Now.AddMinutes(-90); 
     // dta.Maximum = DateTime.Now; 

     LinearAxis yaxis = new LinearAxis(); 
     yaxis.Minimum = 0; 
     yaxis.Interval = 2; 
     yaxis.Title = "Case"; 
     yaxis.Orientation = AxisOrientation.Y; 
     yaxis.ShowGridLines = true; 
     chart1.Axes.Add(yaxis); 
     chart1.Axes.Add(dta); 
     chart1.Series.Add(ares); 



    } 

    private void Button_Click(object sender, RoutedEventArgs e) 
    { 
     LoadData(); 
     chart1.UpdateLayout(); 

    } 



} 

}

データ・モデルは、ここで

あります
class Ready4LOS : INotifyPropertyChanged 
{ 
    int _case; 
    DateTime _time; 

    public int Case 
    { 
     get 
     { 
      return _case; 

     } 

     set 
     { 
      _case = value; 
      NotifyPropertyChanged("Case"); 
     } 
    } 

    public DateTime Time 
    { 
     get 
     { 
      return _time; 
     } 

     set 
     { 
      _time = value; 
      NotifyPropertyChanged("Time"); 
     } 
    } 



    public event PropertyChangedEventHandler PropertyChanged; 
    private void NotifyPropertyChanged(String info) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(info)); 
     } 
    } 
} 

私はLoadData()を最初に呼び出したので、開始時に完全にロードされます。 問題は、リフレッシュボタンをクリックしてソースオブジェクト内のデータを読み込みますが、ターゲットオブジェクトのデータは更新されません。つまり、チャートは更新されず、初期データと同じになります。

答えて

1

ObservableCollection<Ready4LOS>ではなくList<Ready4LOS>を使用してください。 ObservableCollection<>は既にINotifyPropertyChangedINotifyCollectionChangedを実装しています。既にコレクション内に存在するReady4LOSCaseTimeの値を動的に変更する場合にのみ、Ready4LOSINotifyPropertyChangedの実装が必要な場合があります。

enter image description here

+0

うわー、私はそれを知らなかった...確かに試してみると、あなたが時間を割いて、私を助けるため – rvsingh42

+0

感謝...特別にあなたがそこに置くことJIFのためにお知らせします。 – rvsingh42

+0

問題はない、私の喜び。 – jsanalytics

関連する問題