Example #1
0
 static LineDataset CreateChartDataSet(string label, List <double?> data)
 {
     return(new LineDataset()
     {
         Label = label,
         Data = data,
         BackgroundColor = ChartColor.CreateRandomChartColor(true),
         BorderColor = ChartColor.CreateRandomChartColor(true),
         PointBorderColor = new List <ChartColor>()
         {
             ChartColor.CreateRandomChartColor(true)
         },
         PointBackgroundColor = new List <ChartColor>()
         {
             ChartColor.CreateRandomChartColor(true)
         },
         PointHoverBackgroundColor = new List <ChartColor>()
         {
             ChartColor.CreateRandomChartColor(true)
         },
         PointHoverBorderColor = new List <ChartColor>()
         {
             ChartColor.CreateRandomChartColor(true)
         },
         Fill = "true"
     });
 }
        public void GetRandomChartColor_With_Random_Alpha_Returns_Values_In_Boundry()
        {
            var randomColor = ChartColor.CreateRandomChartColor(true);

            Assert.That(randomColor.Red, Is.GreaterThanOrEqualTo(0).And.LessThanOrEqualTo(256));
            Assert.That(randomColor.Green, Is.GreaterThanOrEqualTo(0).And.LessThanOrEqualTo(256));
            Assert.That(randomColor.Blue, Is.GreaterThanOrEqualTo(0).And.LessThanOrEqualTo(256));
            Assert.That(randomColor.Alpha, Is.GreaterThanOrEqualTo(0.0).And.LessThanOrEqualTo(1.0));
        }
        public void GetRandomChartColor_Without_Random_Alpha_Returns_Values_In_Boundry_And_Alpha_One()
        {
            double expectedAlpha = 1.0;

            var randomColor = ChartColor.CreateRandomChartColor(false);

            Assert.That(randomColor.Red, Is.GreaterThanOrEqualTo(0).And.LessThanOrEqualTo(256));
            Assert.That(randomColor.Green, Is.GreaterThanOrEqualTo(0).And.LessThanOrEqualTo(256));
            Assert.That(randomColor.Blue, Is.GreaterThanOrEqualTo(0).And.LessThanOrEqualTo(256));
            Assert.AreEqual(randomColor.Alpha, expectedAlpha);
        }
Example #4
0
        private static Chart GetPercentagePerCountryChart(Dictionary <string, double> percentagePerCountry)
        {
            var chart = new Chart {
                Type = Enums.ChartType.Doughnut
            };
            var data = new ChartJSCore.Models.Data
            {
                Labels = percentagePerCountry.Keys.ToList()
            };
            var dataset = new PieDataset
            {
                Label           = "# hours watched",
                Data            = new List <double?>(percentagePerCountry.Values.Select(x => (double?)x)),
                BorderWidth     = 1,
                BackgroundColor = new List <ChartColor>(),
                Type            = Enums.ChartType.Doughnut,
            };

            for (int i = 0; i < percentagePerCountry.Count; i++)
            {
                dataset.BackgroundColor.Add(ChartColor.CreateRandomChartColor(false));
            }

            data.Datasets = new List <Dataset> {
                dataset
            };
            chart.Data    = data;
            chart.Options = new PieOptions
            {
                Responsive          = true,
                MaintainAspectRatio = false,
                Title = new Title {
                    Text = "Watched per country (in percentage)", Display = true
                },
                ResponsiveAnimationDuration = 500
            };

            return(chart);
        }