Exemplo n.º 1
0
        SfChart CreateChart(JournalMonth month)
        {
            _points = new ObservableCollection <ChartDataPoint>();

            SfChart chart = new SfChart()
            {
                HeightRequest = 250
            };

            chart.Title.Text = "Monthly Emotion Overview";

            PieSeries series = new PieSeries()
            {
                XBindingPath = "Emotion",
                YBindingPath = "Value"
            };

            series.ColorModel.Palette      = ChartColorPalette.Custom;
            series.DataMarker              = new ChartDataMarker();
            series.DataMarkerPosition      = CircularSeriesDataMarkerPosition.OutsideExtended;
            series.DataMarker.LabelContent = LabelContent.Percentage;

            series.ColorModel.CustomBrushes.Clear();
            chart.Legend = new ChartLegend();

            Emotion        emotion  = Emotion.None;
            List <Emotion> emotions = DreamsAPI.GetEmotions();

            for (int index = 0; index < emotions.Count; index++)
            {
                emotion = emotions[index];
                List <DreamRecord> records = new List <DreamRecord>(from rec in month.Records
                                                                    where rec.Emotion == emotion
                                                                    select rec);
                _points.Add(new ChartDataPoint(emotion.ToString(), records.Count));
                series.ColorModel.CustomBrushes.Add(DreamsAPI.GetEmotionColor(emotion));
            }

            series.ItemsSource = _points;

            chart.Series.Add(series);

            return(chart);
        }
Exemplo n.º 2
0
        SfChart CreateWeeklyChart()
        {
            FilterIntoEmotions();

            SfChart chart = new SfChart()
            {
                HeightRequest = 250
            };

            chart.Title.Text = "Your Last Seven Days";

            //Initializing Primary Axis
            DateTimeAxis primaryAxis = new DateTimeAxis()
            {
                Interval           = 1,
                IntervalType       = DateTimeIntervalType.Days,
                ShowMajorGridLines = false,
                ShowMinorGridLines = false
            };

            primaryAxis.LabelStyle.LabelFormat = "MMM dd";

            primaryAxis.Title = new ChartAxisTitle()
            {
                Text = "Day",
            };

            chart.PrimaryAxis = primaryAxis;

            //Initializing Secondary Axis
            NumericalAxis secondaryAxis = new NumericalAxis()
            {
                Interval           = 1,
                ShowMinorGridLines = false
            };

            secondaryAxis.Title = new ChartAxisTitle()
            {
                Text = "Num. Dreams",
            };

            chart.SecondaryAxis = secondaryAxis;

            chart.Legend = new ChartLegend();

            foreach (KeyValuePair <Emotion, ObservableCollection <ChartDataPoint> > pair
                     in _seriesData)
            {
                StackingColumnSeries series = new StackingColumnSeries()
                {
                    ItemsSource  = pair.Value,
                    XBindingPath = "Day",
                    YBindingPath = "Value",
                    Color        = DreamsAPI.GetEmotionColor(pair.Key),
                    Label        = pair.Key.ToString()
                };

                chart.Series.Add(series);
            }

            return(chart);
        }