Ejemplo n.º 1
0
        private void TimerElapsed(object sender, EventArgs e)
        {
            {
                // SuspendUpdates() ensures the chart is frozen
                // while you do updates. This ensures best performance
                using (_originalData.SuspendUpdates())
                {
                    while (nDataPure.Count > Constants.BUFLENCHECK)
                    {
                        // Append a new data point;
                        Int32 localvalue;
                        if (nDataPure.TryDequeue(out localvalue))
                        {
                            _originalData.Append(_sci_timeIndex.getIndex_double(), localvalue);
                            _filterData.Append(_sci_timeIndex.getIndex_double(), localvalue);
                            _sci_timeIndex.Increment();
                        }
                        //scatterData.Append(i, Math.Cos(i * 0.1));
                    }

                    // Set VisibleRange to last 1,000 points
                    sciChartSurface.XAxis.VisibleRange = new DoubleRange(_sci_timeIndex.getIndex_double() - _sci_timeIndex.getVisibleRange_double(), _sci_timeIndex.getIndex_double());
                }
            }
        }
Ejemplo n.º 2
0
        private void AddNewCandle(Candle candle, double?indicatorValue1, double?indicatorValue2, double?indicatorValue3)
        {
            using (ohlcSeries.SuspendUpdates())
                using (BBMiddleSeries.SuspendUpdates())
                    using (BBUpperSeries.SuspendUpdates())
                        using (BBLowerSeries.SuspendUpdates())
                        {
                            candlesCount++;
                            ohlcSeries.Append(candle.Time, (double)candle.Open, (double)candle.High, (double)candle.Low, (double)candle.Close);
                            StockChart.XAxis.VisibleRange = new IndexRange(candlesCount - 50, candlesCount);

                            if (indicatorValue1 != null)
                            {
                                BBMiddleSeries.Append(candle.Time, indicatorValue1.Value);
                            }
                            if (indicatorValue2 != null)
                            {
                                BBUpperSeries.Append(candle.Time, indicatorValue2.Value);
                            }
                            if (indicatorValue3 != null)
                            {
                                BBLowerSeries.Append(candle.Time, indicatorValue3.Value);
                            }
                        }
        }
        // The second method of updating a realtime chart: Appending Data values
        private void Method2_AppendingDataValues()
        {
            var scatterData = new XyDataSeries <double, double>();
            var lineData    = new XyDataSeries <double, double>();

            // Ensure that DataSeries are named for the legend
            scatterData.SeriesName   = "Cos(x)";
            lineData.SeriesName      = "Sin(x)";
            LineSeries.DataSeries    = lineData;
            ScatterSeries.DataSeries = scatterData;
            // Start a timer to update our data
            var timer = new DispatcherTimer(DispatcherPriority.Render);

            timer.Interval = TimeSpan.FromMilliseconds(10);
            timer.Tick    += (s, e) =>
            {
                // This time we will append, not update.
                using (lineData.SuspendUpdates())
                    using (scatterData.SuspendUpdates())
                    {
                        int i = lineData.Count;
                        // Append a new data point;
                        lineData.Append(i, Math.Sin(i * 0.1));
                        scatterData.Append(i, Math.Cos(i * 0.1));
                        // ZoomExtents after appending data.
                        // Also see XAxis.AutoRange, and XAxis.VisibleRange for more options
                        sciChartSurface.ZoomExtents();
                    }
            };
            timer.Start();
        }
Ejemplo n.º 4
0
        private void AddNewCandle(Candle candle, decimal indicator)
        {
            using (dataSeries.SuspendUpdates())
                using (ohlcSeries.SuspendUpdates())
                {
                    ohlcSeries.Append(candle.Time, (double)candle.Open, (double)candle.High, (double)candle.Low, (double)candle.Close);
                    dataSeries.Append(candle.Time, (double)indicator);
                    candleCount++;

                    StockChart.XAxis.VisibleRange = new IndexRange(candleCount - 50, candleCount);


                    // DateTime d = candle.Time;
                    indicatorChar.XAxis.VisibleRange = new IndexRange(candleCount - 50, candleCount);
                }
        }
Ejemplo n.º 5
0
 private void UpdateDataOnTimerTick()
 {
     using (_xyDataSeries.SuspendUpdates())
     {
         UpdateXyDataSeries();
         UpdateSpectrogramHeatmapSeries(_xyDataSeries);
     }
 }
Ejemplo n.º 6
0
        private void OnLoadedPreserveOldAndAllowZoom(object sender, RoutedEventArgs routedEventArgs)
        {
            // Instantiate the ViewportManager here
            double windowSize = 1000.0;

            sciChartSurface.ViewportManager = new ScrollingViewportManager(windowSize);

            // Create XyDataSeries to host data for our charts
            var scatterData = new XyDataSeries <double, double>()
            {
                SeriesName = "Cos(x)"
            };
            var lineData = new XyDataSeries <double, double>()
            {
                SeriesName = "Sin(x)"
            };

            // Assign dataseries to RenderSeries
            LineSeries.DataSeries     = lineData;
            ScatterSeries.DataSeries  = scatterData;
            mountainSeries.DataSeries = scatterData;

            int i = 0;

            // Start a timer to update our data
            // APPEND
            var timer = new DispatcherTimer(DispatcherPriority.Render);

            timer.Interval = TimeSpan.FromMilliseconds(10);
            timer.Tick    += (s, e) =>
            {
                using (lineData.SuspendUpdates())
                    using (scatterData.SuspendUpdates())
                    {
                        // Append new data point
                        lineData.Append(i, Math.Sin(i * 0.1));
                        scatterData.Append(i, Math.Cos(i * 0.1));
                        // Every 100th datapoint, add an annotation
                        if (i % 100 == 0)
                        {
                            var isSecond = i % 200 == 0;
                            sciChartSurface.Annotations.Add(new InfoAnnotation()
                            {
                                X1      = i,
                                Y1      = isSecond ? Math.Cos(i * 0.1) : Math.Sin(i * 0.1),
                                YAxisId = isSecond ? "Axis2" : AxisBase.DefaultAxisId
                            });
                            // It does not work, I don't know why?
                            // Optional: Don't forget to remove annotations which are out of range!
                            sciChartSurface.Annotations.RemoveWhere(x => x.X1.ToDouble() < i - 1000);
                        }
                        i++;
                    }
            };
            timer.Start();
        }
        public void OffsetSeries(XyDataSeries <DateTime, double> series, double offset)
        {
            var originalXData = series.XValues.ToArray();
            var originalYData = series.YValues.ToArray();

            // To Offset the series, clear and recreate data
            using (series.SuspendUpdates())
            {
                series.Clear();
                series.Append(originalXData, originalYData.Select(y => y + offset));
            }
        }
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            // Instantiate the ViewportManager here
            double windowSize = 1000.0;

            sciChartSurface.ViewportManager = new ScrollingViewportManager(windowSize);

            // Create DataSeries with FifoCapacity
            var scatterData = new XyDataSeries <double, double>()
            {
                SeriesName = "Cos(x)",
            };
            var lineData = new XyDataSeries <double, double>()
            {
                SeriesName = "Sin(x)",
            };

            // Assign DataSeries to RenderableSeries
            LineSeries.DataSeries     = lineData;
            ScatterSeries.DataSeries  = scatterData;
            mountainSeries.DataSeries = scatterData; // <-- NEW CODE HERE!
            int i = 0;
            // Start a timer to update our data
            var timer = new DispatcherTimer(DispatcherPriority.Render);

            timer.Interval = TimeSpan.FromMilliseconds(10);
            timer.Tick    += (s, e) =>
            {
                // This time we will append, not update.
                using (lineData.SuspendUpdates())
                    using (scatterData.SuspendUpdates())
                    {
                        // Append a new data point;
                        lineData.Append(i, Math.Sin(i * 0.1));
                        scatterData.Append(i, Math.Cos(i * 0.1));
                        // Every 100th datapoint, add an annotation
                        if (i % 100 == 0)
                        {
                            sciChartSurface.Annotations.Add(new InfoAnnotation()
                            {
                                X1      = i,
                                Y1      = 0.0,
                                YAxisId = i % 200 == 0 ? AxisBase.DefaultAxisId : "Axis2"
                            });
                            // Optional: Don't forget to remove annotations which are out of range!
                            sciChartSurface.Annotations.RemoveWhere(x => x.X1.ToDouble() < i - 1000);
                        }
                        i++;
                    }
            };
            timer.Start();
        }
Ejemplo n.º 9
0
 private void AddNewCandle(Candle candle, decimal indicator)
 {
     using (macdDataSeries.SuspendUpdates())
         using (dataSeries.SuspendUpdates())
             using (ohlcSeries.SuspendUpdates())
             {
                 ohlcSeries.Append(candle.Time, (double)candle.Open, (double)candle.High, (double)candle.Low, (double)candle.Close);
                 macdDataSeries.Append(candle.Time, macdPoints[candleCount].Macd, macdPoints[candleCount].Signal);
                 candleCount++;
                 dataSeries.Append(candle.Time, (double)Monitor.Indicator.Calculate(candle));
                 StockChart.XAxis.VisibleRange    = new IndexRange(candleCount - 50, candleCount);
                 indicatorChar.XAxis.VisibleRange = new IndexRange(candleCount - 50, candleCount);
             }
 }
Ejemplo n.º 10
0
        private void OnTimerTick(object sender, EventArgs e)
        {
            _yNext = _yNext + ((float)_random.NextDouble() - 0.5f);

            using (_xyDataSeries.SuspendUpdates())
            {
                if (_index == 999)
                {
                    // wrap around. Break the line with nan
                    _xyDataSeries.Append(_index + 1, float.NaN);
                    _index = 0;
                }

                _xyDataSeries.Update(_index++, _yNext);
            }
        }
Ejemplo n.º 11
0
        private void AddNewCandle(Candle candle, double?indicatorValue)
        {
            using (ohlcSeries.SuspendUpdates())
                using (sarSeries.SuspendUpdates())
                {
                    ohlcSeries.Append(candle.Time, (double)candle.Open, (double)candle.High, (double)candle.Low, (double)candle.Close);

                    if (indicatorValue != null)
                    {
                        sarSeries.Append(candle.Time, indicatorValue.Value);
                    }

                    candlesCount++;

                    StockChart.XAxis.VisibleRange = new IndexRange(candlesCount - 50, candlesCount);
                }
        }
        // The final method of updating a realtime chart. Using a ViewportManager to allow zooming + scrolling at the same time
        private void Method4_ScrollingAndAllowingZooming()
        {
            // Instantiate the ViewportManager here
            double windowSize = 1000.0;

            sciChartSurface.ViewportManager = new ScrollingViewportManager(windowSize);

            // Create DataSeries with FifoCapacity
            var scatterData = new XyDataSeries <double, double>()
            {
                SeriesName = "Cos(x)",
            };
            var lineData = new XyDataSeries <double, double>()
            {
                SeriesName = "Sin(x)",
            };

            // Assign DataSeries to RenderableSeries
            LineSeries.DataSeries    = lineData;
            ScatterSeries.DataSeries = scatterData;
            int i = 0;
            // Start a timer to update our data
            var timer = new DispatcherTimer(DispatcherPriority.Render);

            timer.Interval = TimeSpan.FromMilliseconds(10);
            timer.Tick    += (s, e) =>
            {
                // This time we will append, not update.
                using (lineData.SuspendUpdates())
                    using (scatterData.SuspendUpdates())
                    {
                        // Append a new data point;
                        lineData.Append(i, Math.Sin(i * 0.1));
                        scatterData.Append(i, Math.Cos(i * 0.1));
                        i++;
                    }
            };
            timer.Start();
        }
Ejemplo n.º 13
0
        private void OnLoadedFifo(object sender, RoutedEventArgs routedEventArgs)
        {
            // Create XyDataSeries to host data for our charts
            var scatterData = new XyDataSeries <double, double>()
            {
                SeriesName = "Cos(x)", FifoCapacity = 1000
            };
            var lineData = new XyDataSeries <double, double>()
            {
                SeriesName = "Sin(x)", FifoCapacity = 1000
            };

            // Assign dataseries to RenderSeries
            LineSeries.DataSeries    = lineData;
            ScatterSeries.DataSeries = scatterData;
            int i = 0;

            // Start a timer to update our data
            // APPEND
            var timer = new DispatcherTimer(DispatcherPriority.Render);

            timer.Interval = TimeSpan.FromMilliseconds(10);
            timer.Tick    += (s, e) =>
            {
                using (lineData.SuspendUpdates())
                    using (scatterData.SuspendUpdates())
                    {
                        // Append new data point
                        lineData.Append(i, Math.Sin(i * 0.1));
                        scatterData.Append(i, Math.Cos(i * 0.1));
                        sciChartSurface.ZoomExtents();
                        // Set VisibleRange to last 1,000 points
                        xAxesNumericAxis.VisibleRange = new DoubleRange(i - 1000, i);
                        i++;
                    }
            };
            timer.Start();
        }
        // The First method of updating a real-time chart: Updating Data Values
        private void Method1_UpdatingDataValues()
        {
            var scatterData = new XyDataSeries <double, double>();
            var lineData    = new XyDataSeries <double, double>();

            // Ensure that DataSeries are named for the legend
            scatterData.SeriesName = "Cos(x)";
            lineData.SeriesName    = "Sin(x)";
            for (int i = 0; i < 1000; i++)
            {
                lineData.Append(i, Math.Sin(i * 0.1));
                scatterData.Append(i, Math.Cos(i * 0.1));
            }
            LineSeries.DataSeries    = lineData;
            ScatterSeries.DataSeries = scatterData;
            // Start a timer to update our data
            double phase = 0.0;
            var    timer = new DispatcherTimer(DispatcherPriority.Render);

            timer.Interval = TimeSpan.FromMilliseconds(10);
            timer.Tick    += (s, e) =>
            {
                // SuspendUpdates() ensures the chart is frozen
                // while you do updates. This ensures best performance
                using (lineData.SuspendUpdates())
                    using (scatterData.SuspendUpdates())
                    {
                        for (int i = 0; i < 1000; i++)
                        {
                            // Updates the Y value at index i
                            lineData.Update(i, Math.Sin(i * 0.1 + phase));
                            scatterData.Update(i, Math.Cos(i * 0.1 + phase));
                        }
                    }
                phase += 0.01;
            };
            timer.Start();
        }
        // The third method of updating a realtime chart: Using FIFO (First in first out) series
        private void Method3_FifoScrollingUpdates()
        {
            // Create DataSeries with FifoCapacity
            var scatterData = new XyDataSeries <double, double>()
            {
                SeriesName = "Cos(x)", FifoCapacity = 1000
            };
            var lineData = new XyDataSeries <double, double>()
            {
                SeriesName = "Sin(x)", FifoCapacity = 1000
            };

            // Assign DataSeries to RenderableSeries
            LineSeries.DataSeries    = lineData;
            ScatterSeries.DataSeries = scatterData;
            int i = 0;
            // Start a timer to update our data
            var timer = new DispatcherTimer(DispatcherPriority.Render);

            timer.Interval = TimeSpan.FromMilliseconds(10);
            timer.Tick    += (s, e) =>
            {
                // This time we will append, not update.
                using (lineData.SuspendUpdates())
                    using (scatterData.SuspendUpdates())
                    {
                        // Append a new data point;
                        lineData.Append(i, Math.Sin(i * 0.1));
                        scatterData.Append(i, Math.Cos(i * 0.1));
                        // Set VisibleRange to last 1,000 points
                        sciChartSurface.XAxis.VisibleRange = new DoubleRange(i - 1000, i);
                        i++;
                    }
            };
            timer.Start();
        }
Ejemplo n.º 16
0
        //добавить новую шкалу в прокручиваемый список
        public void AddNewChart(string name)
        {
            surfaces.Add(new SciChartSurface());
            SciChartSurface justAdded = surfaces[surfaces.Count - 1];

            justAdded.Name = name;

            justAdded.Height = 200;
            justAdded.Width  = 370;

            // Create the X and Y Axis
            var xAxis = new NumericAxis()
            {
                AxisTitle = "Секунд с момента наблюдения"
            };
            var yAxis = new NumericAxis()
            {
                AxisTitle = "Текущее значение"
            };

            justAdded.XAxis = xAxis;
            justAdded.YAxis = yAxis;

            justAdded.YAxis.AutoRange = AutoRange.Always;

            FastLineRenderableSeries fastLine = new FastLineRenderableSeries();

            fastLine.Name   = "LineSeries";
            fastLine.Stroke = (Color)ColorConverter.ConvertFromString("#FF4083B7");

            justAdded.RenderableSeries.Add(fastLine);

            // Specify Interactivity Modifiers
            //justAdded.ChartModifier = new ModifierGroup(new RubberBandXyZoomModifier(), new ZoomExtentsModifier());
            // Add annotation hints to the user

            //добавить элемент как новый Item в ScrollViewer
            ChartsPanel.Children.Add(justAdded);

            var label = new Label();

            label.Height  = 70;
            label.Content = "";

            ChartsPanel.Children.Add(label);

            //добавить обновление первого чарта в реальном времени
            // Create DataSeries with FifoCapacity
            var lineData = new XyDataSeries <double, double>()
            {
                SeriesName = "Sin(x)", FifoCapacity = 1000
            };

            //// Assign DataSeries to RenderableSeries
            fastLine.DataSeries = lineData;
            int i = 0;
            // Start a timer to update our data
            var timer = new DispatcherTimer(DispatcherPriority.Render);

            timer.Interval = TimeSpan.FromMilliseconds(1000);
            timer.Tick    += (s, e) =>
            {
                // This time we will append, not update.
                using (lineData.SuspendUpdates())
                {
                    // Append a new data point;
                    lineData.Append(i, 0);
                    // Set VisibleRange to last 1,000 points

                    justAdded.XAxis.VisibleRange = new DoubleRange(i - 15, i);
                    i++;
                }
            };
            timer.Start();
        }
Ejemplo n.º 17
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            // Create XyDataSeries to host data for our charts
            var scatterData = new XyDataSeries <double, double>();
            var lineData    = new XyDataSeries <double, double>();

            // Ensure that DataSeries are named for the legend
            scatterData.SeriesName = "Cos(x)";
            lineData.SeriesName    = "Sin(x)";

            for (int i = 0; i < 1000; i++)
            {
                lineData.Append(i, Math.Sin(i * 0.1));
                scatterData.Append(i, Math.Cos(i * 0.1));
            }

            // Assign dataseries to RenderSeries
            LineSeries.DataSeries    = lineData;
            ScatterSeries.DataSeries = scatterData;

            // Start a timer to update our data

            // UPDATE
            //double phase = 0.0;
            //var timer = new DispatcherTimer(DispatcherPriority.Render);
            //timer.Interval = TimeSpan.FromMilliseconds(10);
            //timer.Tick += (s, e) =>
            //{
            //    // SuspendUpdates() ensures the chart is frozen
            //    // while you do updates. This ensures best performance
            //    using (lineData.SuspendUpdates())
            //    using (scatterData.SuspendUpdates())
            //    {
            //        for (int i = 0; i < 1000; i++)
            //        {
            //            lineData.Update(i, Math.Sin(i * 0.1 + phase));
            //            scatterData.Update(i, Math.Cos(i * 0.1 + phase));
            //        }
            //    }
            //    phase += 0.01;
            //};
            //timer.Start();

            // APPEND
            var timer = new DispatcherTimer(DispatcherPriority.Render);

            timer.Interval = TimeSpan.FromMilliseconds(10);
            timer.Tick    += (s, e) =>
            {
                using (lineData.SuspendUpdates())
                    using (scatterData.SuspendUpdates())
                    {
                        int i = lineData.Count;
                        // Console.WriteLine("count i: " + i);
                        // Append new data point
                        lineData.Append(i, Math.Sin(i * 0.1));
                        scatterData.Append(i, Math.Cos(i * 0.1));
                        sciChartSurface.ZoomExtents();
                    }
            };
            timer.Start();
        }