/// <summary>
        /// Sets up the line chart series.
        /// </summary>
        protected override void SetupSeries()
        {
            // If no books return the default.
            if (BooksReadProvider == null)
            {
                base.SetupSeries();
                return;
            }

            // Set up the axis names and formatters.
            XAxisTitle = "Month of the year";
            YAxisTitle = "Pages Read";

            // get the books & pages read for each calendar year
            Dictionary <int, List <MonthOfYearTally> > bookListsByMonthOfYear =
                BookTotalsUtilities.GetBookListsByMonthOfYear(BooksReadProvider);

            // Set up the series for the overall and the trendline.
            Series = new SeriesCollection();
            List <ISeriesView> seriesViews = new List <ISeriesView>();

            MinY = 0;
            MaxY = 1;

            // Add a series for each year.
            List <Color> stdColors   = ColorUtilities.SetupStandardColourSet();
            int          colourIndex = 0;

            foreach (int year in bookListsByMonthOfYear.Keys.ToList().OrderBy(x => x))
            {
                // Get the totals for the months.
                List <double> pagesReadSeriesValues = new List <double>();
                List <double> months = new List <double>();
                double        total  = 0;
                for (int i = BookTotalsUtilities.FirstMonth; i <= BookTotalsUtilities.LastMonth; i++)
                {
                    // Get the tally for this month if set and add it to the total
                    MonthOfYearTally tally = bookListsByMonthOfYear[year].FirstOrDefault(x => x.MonthOfYear == i);
                    months.Add(i);
                    total += tally?.PagesReadThisMonth ?? 0;
                    pagesReadSeriesValues.Add(total);
                }

                // Create the series for the year.
                Color color = stdColors[colourIndex % stdColors.Count];
                seriesViews.Add(CreateLineSeries(year.ToString(), months, pagesReadSeriesValues, color, 0d));
                colourIndex++;

                // Update the Y-range.
                MinY = Math.Floor(Math.Min(pagesReadSeriesValues.Min(), MinY));
                MaxY = Math.Ceiling(Math.Max(pagesReadSeriesValues.Max(), MaxY));
            }

            Series.AddRange(seriesViews);
            SeriesCollection = Series;

            // Update the X-range.
            MinTick = BookTotalsUtilities.FirstMonth - 1;
            MaxTick = BookTotalsUtilities.LastMonth + 1;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets up the pie chart series.
        /// </summary>
        protected override void SetupSeries()
        {
            // If no books return the default.
            if (BooksReadProvider == null)
            {
                base.SetupSeries();
                return;
            }

            // Get the sorted books.
            List <KeyValuePair <string, int> > sortedCountryTotals =
                BookTotalsUtilities.SortedSortedBooksReadByCountryTotals(BooksReadProvider);

            // Set up the series per county.
            Series = new SeriesCollection();
            List <ISeriesView> seriesViews = new List <ISeriesView>();
            List <Color>       colors      = ColorUtilities.SetupStandardColourSet();

            for (int i = 0; i < sortedCountryTotals.Count; i++)
            {
                KeyValuePair <string, int> countryTotal = sortedCountryTotals[i];
                Color color = colors[i % colors.Count];
                seriesViews.Add(CreatePieSeries(countryTotal.Key, countryTotal.Value, color));
            }

            Series.AddRange(seriesViews);
            SeriesCollection = Series;
        }
        /// <summary>
        /// Sets up the line chart series.
        /// </summary>
        protected override void SetupSeries()
        {
            // If no books return the default.
            if (BooksReadProvider == null)
            {
                base.SetupSeries();
                return;
            }

            // Set the categories.
            Categories = BookTotalsUtilities.MonthNames.Skip(1).Take(12).ToArray();

            // Set up the axis names and formatters.
            XAxisTitle = "Month of the year";
            YAxisTitle = "Books Read";

            // get the books & pages read for each calendar year
            Dictionary <int, List <MonthOfYearTally> > bookListsByMonthOfYear =
                BookTotalsUtilities.GetBookListsByMonthOfYear(BooksReadProvider);

            // Set up the series collection and initialise the min and max.
            Series = new SeriesCollection();
            List <ISeriesView> seriesViews = new List <ISeriesView>();

            MinY = 0;
            MaxY = 1;

            // Add a series for each year.
            List <Color> stdColors   = ColorUtilities.SetupStandardColourSet();
            int          colourIndex = 0;

            foreach (int year in bookListsByMonthOfYear.Keys.ToList().OrderBy(x => x))
            {
                // Get the totals for the months.
                List <double> booksReadSeriesValues = new List <double>();
                for (int i = BookTotalsUtilities.FirstMonth; i <= BookTotalsUtilities.LastMonth; i++)
                {
                    // Get the tally for this month if set, otherwise set to zero
                    MonthOfYearTally tally = bookListsByMonthOfYear[year].FirstOrDefault(x => x.MonthOfYear == i);
                    booksReadSeriesValues.Add(tally?.BooksReadThisMonth ?? 0);
                }

                // Create the series for the year.
                Color color = stdColors[colourIndex % stdColors.Count];
                seriesViews.Add(CreateColumnSeries(year.ToString(), booksReadSeriesValues, color, 0d));
                colourIndex++;

                // Update the Y-range.
                MinY = Math.Floor(Math.Min(booksReadSeriesValues.Min(), MinY));
                MaxY = Math.Ceiling(Math.Max(booksReadSeriesValues.Max(), MaxY));
            }

            Series.AddRange(seriesViews);
            SeriesCollection = Series;
        }
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            PlotModel newPlot = new PlotModel {
                Title = "Current Books Read by Country"
            };

            OxyPlotUtilities.SetupPlotLegend(newPlot, "Current Books Read by Country");

            List <KeyValuePair <string, int> > sortedCountryTotals =
                BookTotalsUtilities.SortedSortedBooksReadByCountryTotals(BooksReadProvider);

            return(OxyPlotUtilities.CreatePieSeriesModelForResultsSet(
                       sortedCountryTotals, "Current Books Read by Country", 128));
        }