private void trackLineEnable_Changed(object sender, RoutedEventArgs e) { if ((null != WPFChartViewer1) && (null != WPFChartViewer1.Chart)) { trackLineLabel((XYChart)WPFChartViewer1.Chart); WPFChartViewer1.updateDisplay(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { // Load the data loadData(); // Initialize the WinChartViewer initChartViewer(WPFChartViewer1); // Trigger the ViewPortChanged event to draw the chart WPFChartViewer1.updateViewPort(true, true); }
// // Update the chart and the viewport periodically // private void chartUpdateTimer_Tick(object sender, EventArgs e) { // Get new data from the queue and append them to the data arrays var packets = buffer.get(); if (packets.Count <= 0) { return; } // if data arrays have insufficient space, we need to remove some old data. if (currentIndex + packets.Count >= sampleSize) { // For safety, we check if the queue contains too much data than the entire data arrays. If // this is the case, we only use the latest data to completely fill the data arrays. if (packets.Count > sampleSize) { packets = new ArraySegment <DataPacket>(packets.Array, packets.Count - sampleSize, sampleSize); } // Remove data older than the time range to leave space for new data. The data removed must // be at least equal to the packet count. int originalIndex = currentIndex; if (currentIndex > 0) { currentIndex -= (int)(Chart.bSearch(timeStamps, 0, currentIndex, timeStamps[currentIndex - 1] - timeRange)); } if (currentIndex > sampleSize - packets.Count) { currentIndex = sampleSize - packets.Count; } for (int i = 0; i < currentIndex; ++i) { int srcIndex = i + originalIndex - currentIndex; timeStamps[i] = timeStamps[srcIndex]; channel1[i] = channel1[srcIndex]; channel2[i] = channel2[srcIndex]; } } // Append the data from the queue to the data arrays for (int n = packets.Offset; n < packets.Offset + packets.Count; ++n) { DataPacket p = packets.Array[n]; timeStamps[currentIndex] = p.elapsedTime; channel1[currentIndex] = p.series0; channel2[currentIndex] = p.series1; ++currentIndex; } WPFChartViewer1.updateViewPort(true, false); }
// // The scroll bar event handler // private void hScrollBar1_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { // When the view port is changed (user drags on the chart to scroll), the scroll bar will get // updated. When the scroll bar changes (eg. user drags on the scroll bar), the view port will // get updated. This creates an infinite loop. To avoid this, the scroll bar can update the // view port only if the view port is not updating the scroll bar. if (!WPFChartViewer1.IsInViewPortChangedEvent) { WPFChartViewer1.ViewPortLeft = hScrollBar1.Value; // Trigger a view port changed event to update the chart WPFChartViewer1.updateViewPort(true, false); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { // Connect the WPFViewPortControl to the WPfChartViewer ViewPortControl1.Viewer = WPFChartViewer1; // Load the data loadData(); // Trigger the ViewPortChanged event to draw the chart WPFChartViewer1.updateViewPort(true, true); // Draw the full thumbnail chart for the ViewPortControl drawFullChart(ViewPortControl1, WPFChartViewer1); }
// // The chartUpdateTimer Tick event - this updates the chart periodicially by raising // viewPortChanged events. // private void chartUpdateTimer_Tick(object sender, EventArgs e) { WPFChartViewer1.updateViewPort(true, false); }
// // Update the chart if the WPFChartViewer size is changed // private void WPFChartViewer1_SizeChanged(object sender, SizeChangedEventArgs e) { WPFChartViewer1.updateViewPort(true, false); }