示例#1
0
        public void ParseChart(Chart chart)
        {
            // Update the title
            Title = chart.Name;

            // Validate the chart
            if (chart.Series.Count == 0)
            {
                return;
            }

            // Build YAxes
            if (YAxesCollection.Count == 0)
            {
                // Chart series have indexes, and can share an yaxis.
                var axesCount = chart.Series.Values.Max(v => v.Index + 1);
                for (int axis = 0; axis < axesCount; axis++)
                {
                    // Get the series shown on this axis
                    var series = chart.Series.Values.Where(v => v.Index == axis);

                    // Create Y axis for the series
                    YAxesCollection.Add(new Axis
                    {
                        // Title is with combined series
                        Title    = string.Join(", ", series.Select(s => s.Name).ToArray()),
                        Position = AxisPosition.RightTop
                    });
                }
            }

            // Build Series
            var yAxeIndex = 0;

            var isNewSeries = SeriesCollection.Count == 0;

            if (isNewSeries)
            {
                // Build the series
                foreach (var quantSeries in chart.Series.Values)
                {
                    var series = BuildSeries(quantSeries);
                    series.ScalesYAt = quantSeries.Index;
                    SeriesCollection.Add(series);
                    yAxeIndex++;
                }

                // Build the summary series
                var summarySeries = BuildSeries(chart.Series.Values.First());
                SummarySeriesCollection.Add(summarySeries);
            }

            // Update the series
            yAxeIndex = 0;
            var lastUpdate = TimeStamp.FromDays(0);

            foreach (var quantSeries in chart.Series.Values)
            {
                var series = SeriesCollection[yAxeIndex];

                var updates = quantSeries.Since(LastUpdated);
                UpdateSeries(series, updates);
                if (yAxeIndex == 0)
                {
                    var summarySeries = SummarySeriesCollection.First();
                    UpdateSeries(summarySeries, updates);
                }

                if (isNewSeries && yAxeIndex == 0)
                {
                    // Use this first series for the from and to view
                    ZoomFrom   = 0;
                    ZoomTo     = quantSeries.Values.Count - 1;
                    lastUpdate = TimeStamp.FromSeconds(quantSeries.Values[quantSeries.Values.Count - 1].x);
                }
                else
                {
                    lastUpdate = TimeStamp.FromSeconds(quantSeries.Values[quantSeries.Values.Count - 1].x);
                }

                yAxeIndex++;
            }

            // Update the last update
            LastUpdated = lastUpdate;
        }