コード例 #1
0
        public void UpdateChart(string chartAreaName, string seriesName, long timestamp, double open, double high, double low, double close)
        {
            var series = ChartSeries.FindByName(seriesName);

            if (series == null)
            {
                return;
            }

            var seriesInfo = _dicChartAreaToSeriesInfo[chartAreaName].Find(s => s.SeriesName == seriesName);

            if (seriesInfo == null)
            {
                return;
            }

            //if the new data already shown in chart, we skip
            if (series.Points.Count > 0 && timestamp <= seriesInfo.MaxTimeData)
            {
                return;
            }

            //remove first elements if gets too much data
            if (series.Points.Count >= _maxNumbars * 10)
            {
                var points = series.Points.ToList();
                points.RemoveRange(0, 9 * _maxNumbars);
                var times  = points.Select(p => p.XValue).ToList();
                var highs  = points.Select(p => p.YValues[0]).ToList();
                var lows   = points.Select(p => p.YValues[1]).ToList();
                var opens  = points.Select(p => p.YValues[2]).ToList();
                var closes = points.Select(p => p.YValues[3]).ToList();
                _chart.InvokeIfRequired(c => series.Points.Clear());
                _chart.InvokeIfRequired(c => series.Points.DataBindXY(times, highs, lows, opens, closes));
            }

            //add the new data to series
            _chart.InvokeIfRequired(c => series.Points.AddXY(timestamp.GetUTCFromUnixTime().ToOADate(), high, low, open, close));
            seriesInfo.MinTimeData = DateTime.FromOADate(series.Points.FirstOrDefault().XValue).GetUnixTimeFromUTC();
            seriesInfo.MaxTimeData = timestamp;

            //seriesInfo.MaxPrice = Math.Max(seriesInfo.MaxPrice, high);
            //seriesInfo.MinPrice = Math.Min(seriesInfo.MinPrice, low);
            this.SetAxisRangeForChartArea(chartAreaName, series, seriesInfo);
        }
コード例 #2
0
        public void InitializeChart(string chartAreaName, string seriesName, IQuoteBasic quote)
        {
            if (quote == null || quote.Count <= 1)
            {
                return;
            }

            var series = ChartSeries.FindByName(seriesName);

            if (series == null)
            {
                return;
            }

            var seriesInfo = _dicChartAreaToSeriesInfo[chartAreaName].Find(s => s.SeriesName == seriesName);

            if (seriesInfo == null)
            {
                return;
            }

            var max_index = quote.Count - 1;
            var min_index = Math.Max(0, max_index - _maxNumbars);
            var times     = quote.Time.GetRange(min_index, max_index - min_index + 1).Select(t => t.GetUTCFromUnixTime().ToOADate()).ToList();
            var high      = quote.High.GetRange(min_index, max_index - min_index + 1).ToList();
            var low       = quote.Low.GetRange(min_index, max_index - min_index + 1).ToList();
            var open      = quote.Open.GetRange(min_index, max_index - min_index + 1).ToList();
            var close     = quote.Close.GetRange(min_index, max_index - min_index + 1).ToList();

            _chart.InvokeIfRequired(c => series.Points.Clear());
            _chart.InvokeIfRequired(c => series.Points.DataBindXY(times, high, low, open, close));

            seriesInfo.MinTimeData = DateTime.FromOADate(times.FirstOrDefault()).GetUnixTimeFromUTC();
            seriesInfo.MaxTimeData = DateTime.FromOADate(times.LastOrDefault()).GetUnixTimeFromUTC();

            this.SetAxisRangeForChartArea(chartAreaName, series, seriesInfo);
        }
コード例 #3
0
        public void UpdateChart(string chartAreaName, string seriesName, IQuoteBasic quote)
        {
            var series = ChartSeries.FindByName(seriesName);

            if (series == null)
            {
                return;
            }

            var seriesInfo = _dicChartAreaToSeriesInfo[chartAreaName].Find(s => s.SeriesName == seriesName);

            if (seriesInfo == null)
            {
                return;
            }

            var sindex = quote.Count - 1;

            while (sindex >= 0 && quote.Time[sindex] > seriesInfo.MaxTimeData)
            {
                --sindex;                                                                //index must be -1 or quote.Time[index] <= maxTimeData
            }
            ++sindex;

            var num = quote.Count - sindex;

            if (num <= 0)
            {
                return;
            }

            if (num > 1)
            {
                var points = series.Points.ToList();
                var lst    = Enumerable.Range(sindex, num).Select(i => new DataPoint(quote.Time[i].GetUTCFromUnixTime().ToOADate(), new List <double> {
                    quote.High[i], quote.Low[i], quote.Open[i], quote.Close[i]
                }.ToArray()));
                points.AddRange(lst);
                _chart.InvokeIfRequired(c => series.Points.DataBindXY(
                                            points.Select(l => l.XValue).ToList(),
                                            points.Select(l => l.YValues[0]).ToList(),
                                            points.Select(l => l.YValues[1]).ToList(),
                                            points.Select(l => l.YValues[2]).ToList(),
                                            points.Select(l => l.YValues[3]).ToList()));
            }
            else //num == 1
            {
                _chart.InvokeIfRequired(c => series.Points.AddXY(quote.LastTime.GetUTCFromUnixTime().ToOADate(), quote.High.Last(), quote.Low.Last(), quote.Open.Last(), quote.Close.Last()));
            }

            //remove first elements if gets too much data
            if (series.Points.Count >= _maxNumbars * 10)
            {
                var points = series.Points.ToList();
                points.RemoveRange(0, 9 * _maxNumbars);
                _chart.InvokeIfRequired(c => series.Points.DataBindXY(
                                            points.Select(l => l.XValue).ToList(),
                                            points.Select(l => l.YValues[0]).ToList(),
                                            points.Select(l => l.YValues[1]).ToList(),
                                            points.Select(l => l.YValues[2]).ToList(),
                                            points.Select(l => l.YValues[3]).ToList()));
            }

            //add the new data to series
            seriesInfo.MinTimeData = DateTime.FromOADate(series.Points.FirstOrDefault().XValue).GetUnixTimeFromUTC();
            seriesInfo.MaxTimeData = DateTime.FromOADate(series.Points.LastOrDefault().XValue).GetUnixTimeFromUTC();

            this.SetAxisRangeForChartArea(chartAreaName, series, seriesInfo);
        }