Esempio n. 1
0
        public void createLineChart(string product, Panel panel)
        {
            panel.Controls.Add(chart);

            chart.Width    = 1200;
            chart.Height   = 500;
            chart.Location = new Point(25, 0);

            preference = connection.GetPreference(product);

            valuesLikes    = new ChartValues <ObservablePoint>();
            valuesDislikes = new ChartValues <ObservablePoint>();

            // Calculate the values in each section, (0 = dislikes, 1 = likes)
            calculatePoints(preference, 1);
            calculatePoints(preference, 0);

            chart.Series = new SeriesCollection
            {
                new LineSeries
                {
                    Title          = "Likes",
                    LineSmoothness = 0,
                    Values         = valuesLikes
                },
                new LineSeries
                {
                    Title          = "Dislikes",
                    LineSmoothness = 0,
                    Values         = valuesDislikes
                }
            };

            chart.AxisX.Add(new Axis
            {
                Title    = "Months",
                Labels   = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Dec" },
                MaxValue = 12,
                BarUnit  = 12,
                MaxRange = 12,
            });

            chart.AxisY.Add(new Axis
            {
                Title          = "Number of Likes",
                MinValue       = 0,
                MaxValue       = 25,
                LabelFormatter = value => value + ""
            });

            chart.LegendLocation = LegendLocation.Top;
        }
Esempio n. 2
0
        public void createPieChart(string product, Panel panel)
        {
            panel.Controls.Add(chart);

            chart.Width    = 300;
            chart.Height   = 300;
            chart.Location = new Point(850, 75);

            Func <ChartPoint, string> labelPoint = chartPoint =>
                                                   string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);

            preference = connection.GetPreference(product);
            List <double> likes    = new List <double>();
            List <double> dislikes = new List <double>();

            for (int i = 0; i < preference.Count; i++)
            {
                if (preference[i].likePreference == "0")
                {
                    dislikes.Add(double.Parse(preference[i].likePreference));
                }
                else if (preference[i].likePreference == "1")
                {
                    likes.Add(double.Parse(preference[i].likePreference));
                }
            }

            chart.Series = new SeriesCollection
            {
                new PieSeries
                {
                    Title  = "Likes",
                    Values = new ChartValues <double> {
                        likes.Count
                    },
                    DataLabels = true,
                    LabelPoint = labelPoint
                },
                new PieSeries
                {
                    Title  = "Dislikes",
                    Values = new ChartValues <double> {
                        dislikes.Count
                    },
                    DataLabels = true,
                    LabelPoint = labelPoint
                },
            };

            chart.DataTooltip.Opacity = 0;
            chart.LegendLocation      = LegendLocation.Bottom;
        }