예제 #1
0
        public void realChart(WinChartViewer viewer)
        {
            if (currentIndex > 0)
            {
                DateTime startDate = timeStamps[0];
                DateTime endDate   = timeStamps[currentIndex - 1];

                double duration    = endDate.Subtract(startDate).TotalSeconds;
                int    zoomInLimit = 10;
                if (duration < chartFullRange)  //initialFullRange: 60?
                //endDate = startDate.AddSeconds(Convert.ToDouble(timeStamps1[currentIndex1])); //initialFullRange: 60?
                {
                    endDate = startDate.AddSeconds(chartFullRange); //initialFullRange: 60?
                }
                int updateType = Chart.ScrollWithMax;
                if (viewer.ViewPortLeft + viewer.ViewPortWidth < 0.999)
                {
                    updateType = Chart.KeepVisibleRange;
                }
                bool axisScaleHasChanged = viewer.updateFullRangeH("x", startDate, endDate, updateType);

                viewer.ZoomInWidthLimit = zoomInLimit / (viewer.getValueAtViewPort("x", 1) -
                                                         viewer.getValueAtViewPort("x", 0));

                if (axisScaleHasChanged || (duration < chartFullRange)) //initialFullRange: 60?
                {
                    viewer.updateViewPort(true, false);
                }
            }
        }
예제 #2
0
        //
        // Update the chart and the viewport periodically
        //
        private void chartUpdateTimer_Tick(object sender, EventArgs e)
        {
            WinChartViewer viewer = winChartViewer1;

            if (currentIndex > 0)
            {
                //
                // As we added more data, we may need to update the full range.
                //

                double startDate = timeStamps[0];
                double endDate   = timeStamps[currentIndex - 1];

                // Use the initialFullRange if this is sufficient.
                double duration = endDate - startDate;
                if (duration < initialFullRange)
                {
                    endDate = startDate + initialFullRange;
                }

                // Update the full range to reflect the actual duration of the data. In this case,
                // if the view port is viewing the latest data, we will scroll the view port as new
                // data are added. If the view port is viewing historical data, we would keep the
                // axis scale unchanged to keep the chart stable.
                int updateType = Chart.ScrollWithMax;
                if (viewer.ViewPortLeft + viewer.ViewPortWidth < 0.999)
                {
                    updateType = Chart.KeepVisibleRange;
                }
                bool axisScaleHasChanged = viewer.updateFullRangeH("x", startDate, endDate, updateType);

                // Set the zoom in limit as a ratio to the full range
                viewer.ZoomInWidthLimit = zoomInLimit / (viewer.getValueAtViewPort("x", 1) -
                                                         viewer.getValueAtViewPort("x", 0));

                // Trigger the viewPortChanged event to update the display if the axis scale has
                // changed or if new data are added to the existing axis scale.
                if (axisScaleHasChanged || (duration < initialFullRange))
                {
                    viewer.updateViewPort(true, false);
                }
            }
        }
예제 #3
0
        //
        // Update the chart and the viewport periodically
        //
        private void chartUpdateTimer_Tick(object sender, EventArgs e)
        {
            WinChartViewer viewer = winChartViewer1;

            // Enables auto scroll if the viewport is showing the latest data before the update
            bool autoScroll = (currentIndex > 0) && (0.01 + viewer.getValueAtViewPort("x",
                                                                                      viewer.ViewPortLeft + viewer.ViewPortWidth) >= timeStamps[currentIndex - 1]);

            // 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 oldest data to leave space for new data. To avoid frequent removal, we ensure at
                // least 5% empty space available after removal.
                int originalIndex = currentIndex;
                currentIndex = sampleSize * 95 / 100 - 1;
                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];
                    dataSeriesA[i] = dataSeriesA[srcIndex];
                    dataSeriesB[i] = dataSeriesB[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;
                dataSeriesA[currentIndex] = p.series0;
                dataSeriesB[currentIndex] = p.series1;
                ++currentIndex;
            }

            //
            // As we added more data, we may need to update the full range.
            //

            double startDate = timeStamps[0];
            double endDate   = timeStamps[currentIndex - 1];

            // Use the initialFullRange (which is 60 seconds in this demo) if this is sufficient.
            double duration = endDate - startDate;

            if (duration < initialFullRange)
            {
                endDate = startDate + initialFullRange;
            }

            // Update the new full data range to include the latest data
            bool axisScaleHasChanged = viewer.updateFullRangeH("x", startDate, endDate,
                                                               Chart.KeepVisibleRange);

            if (autoScroll)
            {
                // Scroll the viewport if necessary to display the latest data
                double viewPortEndPos = viewer.getViewPortAtValue("x", timeStamps[currentIndex - 1]);
                if (viewPortEndPos > viewer.ViewPortLeft + viewer.ViewPortWidth)
                {
                    viewer.ViewPortLeft = viewPortEndPos - viewer.ViewPortWidth;
                    axisScaleHasChanged = true;
                }
            }

            // Set the zoom in limit as a ratio to the full range
            viewer.ZoomInWidthLimit = zoomInLimit / (viewer.getValueAtViewPort("x", 1) -
                                                     viewer.getValueAtViewPort("x", 0));

            // Trigger the viewPortChanged event. Updates the chart if the axis scale has changed
            // (scrolling or zooming) or if new data are added to the existing axis scale.
            viewer.updateViewPort(axisScaleHasChanged || (duration < initialFullRange), false);
        }