/// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            var newPlot = new PlotModel {
                Title = "Total Books Read by Language With Time Plot"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Total Books Read by Language With Time Plot");
            SetupTotalBooksReadKeyVsTimeAxes(newPlot);

            // get the languages (in order)
            BooksDelta.DeltaTally latestTally = BooksReadProvider.BookDeltas.Last().OverallTally;
            List <string>         countries   = (from item in latestTally.CountryTotals
                                                 orderby item.Item2 descending
                                                 select item.Item1).ToList();

            // create the series for the languages
            List <KeyValuePair <string, LineSeries> > lineSeriesSet =
                new List <KeyValuePair <string, LineSeries> >();

            for (int i = 0; i < countries.Count; i++)
            {
                LineSeries series;
                OxyPlotUtilities.CreateLongLineSeries(out series,
                                                      ChartAxisKeys.DateKey, ChartAxisKeys.TotalBooksReadKey, countries[i], i, 128);
                lineSeriesSet.Add(
                    new KeyValuePair <string, LineSeries>(countries[i], series));
            }

            // loop through the deltas adding points for each of the items to the lines
            foreach (var delta in BooksReadProvider.BookDeltas)
            {
                var date = DateTimeAxis.ToDouble(delta.Date);
                foreach (var line in lineSeriesSet)
                {
                    double ttl = 0.0;
                    foreach (var langTotal in delta.OverallTally.CountryTotals)
                    {
                        if (langTotal.Item1 == line.Key)
                        {
                            ttl = langTotal.Item2;
                        }
                    }
                    line.Value.Points.Add(new DataPoint(date, ttl));
                }
            }

            IList <LineSeries> lineSeries =
                (from item in lineSeriesSet select item.Value).ToList();
            var stackSeries = OxyPlotUtilities.StackLineSeries(lineSeries);

            // add them to the plot
            foreach (var areaSeries in stackSeries)
            {
                newPlot.Series.Add(areaSeries);
            }

            // finally update the model with the new plot
            return(newPlot);
        }
コード例 #2
0
        public override void UpdateModel(ref PlotModel newPlot)
        {
            OxyPlotUtilities.SetupPlotLegend(newPlot, PlotTitle);
            SetupTotalSeatsVsTimeAxes(newPlot);

            // if no data stop
            if (ElectionPredictions?.PollingPredictions == null ||
                !ElectionPredictions.PollingPredictions.Any())
            {
                return;
            }

            // Get the polls by date.
            List <KeyValuePair <DateTime, PartyPrediction> > pollValues =
                GetPartyPredictionsByDate();

            // Get the party names.
            string[] partiesNames = PartyPrediction.PartiesList;

            // Add a line and a scatter series per party
            List <KeyValuePair <string, LineSeries> > partiesLineSeries =
                new List <KeyValuePair <string, LineSeries> >();

            SetupPartiesSeries(partiesNames, partiesLineSeries);

            // loop through the polls adding points for each of the items to the lines
            AddValuesToSeries(pollValues, partiesLineSeries);

            // Get the area stack series
            IEnumerable <AreaSeries> stackedSeatsSeries =
                OxyPlotUtilities.StackLineSeries(partiesLineSeries.Select(x => x.Value).ToList());

            // add them to the plot
            foreach (AreaSeries series in stackedSeatsSeries)
            {
                newPlot.Series.Add(series);
            }

            // add a line annotation
            double X = 5D;
            double Y = 65D;

            LineAnnotation lineAnnotation = new LineAnnotation()
            {
                StrokeThickness = 3,
                Color           = OxyColors.Crimson,
                Type            = LineAnnotationType.Horizontal,
                Text            = "Majority",
                TextColor       = OxyColors.Crimson,
                X = X,
                Y = Y
            };

            newPlot.Annotations.Add(lineAnnotation);
        }