// Called when the AppendDataCommand is invoked via button click on the view
        private void AppendData()
        {
            var newData = _dataSource.GetRandomWalkSeries(50);

            _dataSeries0.Append(newData.XData, newData.YData);
            ViewportManager.ZoomExtents();
        }
        private void OnRunExample()
        {
            Messages.Clear();
            OpacityParamsForInstructions = null;

            Task.Factory.StartNew(() =>
            {
                // Add DataSeries for the candlestick and SMA series
                var ds0 = new OhlcDataSeries <DateTime, double>()
                {
                    SeriesName = "$SPX500"
                };
                var ds1 = new XyDataSeries <DateTime, double>()
                {
                    SeriesName = "MA 200"
                };
                var ds2 = new XyDataSeries <DateTime, double>()
                {
                    SeriesName = "MA 50"
                };

                Messages.Add("Generating 1M candlesticks ...");
                // Append historical bars to data series
                var prices = _marketDataService.GetHistoricalData(1000000);

                Messages.Add("Appending Data to chart ...");
                ds0.Append(
                    prices.Select(x => x.DateTime),
                    prices.Select(x => x.Open),
                    prices.Select(x => x.High),
                    prices.Select(x => x.Low),
                    prices.Select(x => x.Close));
                //ds1.Append(prices.Select(x => x.DateTime), prices.Select(y => _sma50.Push(y.Close).Current));

                PriceSeries = ds0;
                Messages.Add("Done!");

                ViewportManager.ZoomExtents();
            });
        }
        private void UpdateHistoryDataSeriesCollection(HistoryDataUpdatedEventArg arg)
        {
            var dataList     = arg.HistoryDataDtos.ToList();
            var timeType     = arg.DataTimeType;
            var dataTypeName = arg.DataTypeName;

            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                SeriesViewModels.Clear();

                if (dataList.Count > 0)
                {
                    int index  = 0;
                    var colors = _colors;
                    foreach (var historyData in dataList)
                    {
                        var ds0 = new XyDataSeries <DateTime, double>()
                        {
                            SeriesName = historyData.pointName
                        };

                        SeriesViewModels.Add(
                            new ChartSeriesViewModel(ds0,
                                                     new FastLineRenderableSeries()
                        {
                            SeriesColor     = colors[index],
                            StrokeThickness = 2,
                            //PointMarker = new EllipsePointMarker()
                            //{
                            //    Fill = colors[index],
                            //    Stroke = colors[index],
                            //    StrokeThickness = 1,
                            //    Width = 3,
                            //    Height = 3,
                            //}
                        }
                                                     ));
                        index++;
                        List <DatavalueDTO> data = historyData.dataValue.OrderBy(d => d.time).ToList();
                        ds0.Append(data.Select(x => x.time), data.Select(y => double.Parse(y.value)));
                    }

                    ViewportManager.ZoomExtents();
                    YAxis.VisibleRange.GrowBy(0.4, 0.4);
                }
            }));

            //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            //{
            //    ResetDataSeries();

            //    if (dataList.Count > 0)
            //    {
            //        foreach (var historyData in dataList)
            //        {
            //            var lineSeries = new LineSeries();
            //            lineSeries.Title = historyData.pointName;
            //            lineSeries.Values = new ChartValues<DateModel>();
            //            lineSeries.LabelPoint = value => $"{value.Y} {historyData.unit}";

            //            foreach (var dataValue in historyData.dataValue)
            //            {
            //                lineSeries.Values.Add(new DateModel { Value = double.Parse(dataValue.value), DateTime = dataValue.time });
            //            }
            //            SeriesCollection.Add(lineSeries);
            //        }
            //        string unit = dataList[0]?.unit;
            //        string dateFormat = string.Empty;
            //        switch (timeType)
            //        {
            //            case TimeType.Day:
            //                dateFormat = "HH:mm";
            //                break;
            //            case TimeType.Month:
            //                dateFormat = "d日 HH:mm";
            //                break;
            //            case TimeType.Year:
            //                dateFormat = "MM月-d日 HH:mm";
            //                break;
            //            default:
            //                break;
            //        }

            //        YFormatter = value => $"{value} {unit}";
            //        XFormatter = value =>
            //        {
            //            if (value > 0)
            //            {
            //                var resultValue = new System.DateTime((long)(value * TimeSpan.FromHours(1).Ticks)).ToString(dateFormat);
            //                return resultValue;
            //            }
            //            else
            //                return "0";
            //        };

            //        var colors = CartesianChart.Colors;
            //        int index = 0;
            //        List<SeriesInfo> seriesList = new List<SeriesInfo>();
            //        foreach (var item in SeriesCollection.Chart.View.ActualSeries)
            //        {
            //            var seriesItem = (item as Series);
            //            if (seriesItem != null)
            //            {

            //                var color = colors.ElementAt(index++);

            //                seriesList.Add(new SeriesInfo()
            //                {
            //                    Title = seriesItem.Title,
            //                    Fill = new SolidColorBrush(color),// == null ? (seriesItem as IFondeable).PointForeround : seriesItem.Fill,
            //                    Stroke = seriesItem.Stroke,
            //                    StrokeThickness = seriesItem.StrokeThickness
            //                });


            //            }
            //        }

            //        SeriesList.AddRange(seriesList);

            //    }
            //    DataTypeName = dataTypeName;
            //}));
        }