private LinearAxis GetAxis(DataFormat format) { return((LinearAxis)this.Axes.First(a => { var tag = (a as FrameworkElement).Tag as DataFormat?; return tag == format; })); }
/** * Callback listens to changes to BindableSeries and updates Chart.Series property accordingly * This implementation is a workaround because the base Chart.Series property is not a dependencyproperty * and cannot be bound to. So we create a BindableSeries property which *can* be bound to, * and then delegate changes to it to the underlying Series property */ private void SeriesChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Remove || e.Action == NotifyCollectionChangedAction.Replace) { _Formats = 0; for (int i = 0; i < e.OldItems.Count; i++) { Remove(((IDataSeries)e.OldItems[i]).Id); } var coll = (IEnumerable <IDataSeries>)sender; for (int i = 0; i < coll.Count(); i++) { _Formats |= coll.ElementAt(i).Format; } } if (e.Action == NotifyCollectionChangedAction.Add || e.Action == NotifyCollectionChangedAction.Replace) { for (int i = 0; i < e.NewItems.Count; i++) { Plot((IDataSeries)e.NewItems[i]); _Formats |= ((IDataSeries)e.NewItems[i]).Format; } } if (e.Action == NotifyCollectionChangedAction.Reset) { Clear(); _Formats = 0; if (((ObservableCollection <IDataSeries>)sender).Count > 0) { foreach (var item in ((ObservableCollection <IDataSeries>)sender)) { Plot(item); _Formats |= item.Format; } } } RefreshAxisVisibilities(); }
/** * This method listens to changes IsVisible property of each series and updates * the _Formats property and axis visibilities based on what series are visible. * Basically this method is responsible for hiding axes that have no visible data */ private void OnSeriesVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e) { var series = (IDataSeries)((CustomLineSeries)sender).DataContext; if ((bool)e.NewValue) { _Formats |= series.Format; } else { _Formats &= ~series.Format; foreach (IDataSeries s in BindableSeries) { if (s.Format == series.Format && s.IsVisible) { _Formats |= series.Format; break; } } } RefreshAxisVisibilities(); }