private void Add(object sender, NotifyCollectionChangedEventArgs args) { if ((args.NewItems == null) || (args.NewItems.Count == 0)) { return; } foreach (object item in args.NewItems) { SeriesDataItem dataItem = item as SeriesDataItem; if (dataItem.Value < 0) { dataItem.Value = 50.0; } if (_chartPoints.Count < _chartPoints.Capacity) { _chartPoints.Add(100.0 - dataItem.Value); DrawSeries(); } else { // shift points in the array for (int i = 1; i < _chartPoints.Count; i++) { _chartPoints[i - 1] = _chartPoints[i]; } _chartPoints[_chartPoints.Count - 1] = 100.0 - dataItem.Value; DrawSeries(); //_chartClock.Controller.Begin(); if (_updateInterval.Ticks > 0) { uiTimer.Stop(); _chartCanvas.SetValue(Canvas.LeftProperty, (double)0); timerFrame = 0.0; uiTimer.Start(); } } } }
private void OnInitialized(object sender, EventArgs e) { _updateInterval = TimeSpan.FromMilliseconds(this.UpdateInterval); //init the items collection _seriesDataItems = new SeriesDataItems(); // initialize chart points buffer _chartPoints = new List <double>(this.Points + 2); // are there items provided inline if (this.ItemsSource == null && this.Items.Count > 0) { foreach (object item in this.Items) { if (item.GetType() == typeof(SeriesDataItem)) { SeriesDataItem dataItem = item as SeriesDataItem; _chartPoints.Add(100.0 - dataItem.Value); } } } else { for (int i = 0; i < _chartPoints.Capacity; i++) { _chartPoints.Add(100.0); } } if (_updateInterval.Ticks > 0) { //start the uitimer uiTimer = new System.Windows.Threading.DispatcherTimer(); uiTimer.Interval = TimeSpan.FromMilliseconds(timerFrameRate); uiTimer.Tick += new EventHandler(uiTimer_Tick); uiTimer.Stop(); } }