protected override void OnInitialized()
        {
            _config = new PieConfig
            {
                Options = new PieOptions
                {
                    Responsive = true,
                    Title      = new OptionsTitle
                    {
                        Display = false,
                        Text    = "ChartJs.Blazor Pie Chart"
                    }
                }
            };

            foreach (string color in new[] { "Red", "Yellow", "Green", "Blue" })
            {
                _config.Data.Labels.Add(color);
            }

            PieDataset <int> dataset = new PieDataset <int>(new[] { 6, 5, 3, 7 })
            {
                BackgroundColor = new[]
                {
                    ColorUtil.ColorHexString(255, 99, 132), // Slice 1 aka "Red"
                    ColorUtil.ColorHexString(255, 205, 86), // Slice 2 aka "Yellow"
                    ColorUtil.ColorHexString(75, 192, 192), // Slice 3 aka "Green"
                    ColorUtil.ColorHexString(54, 162, 235), // Slice 4 aka "Blue"
                }
            };

            _config.Data.Datasets.Add(dataset);
        }
Esempio n. 2
0
        public static string[] RandomColors(int quantity, int brightness)
        {
            Random r = new Random();

            string[] s = new string[quantity];

            Vector3 color  = new Vector3(brightness, brightness, brightness);
            float   lenght = color.Length();

            //Vector3 color2 = Vector3.Normalize(new Vector3(r.Next(255), r.Next(255), r.Next(255)));

            for (int i = 0; i < quantity; i++)
            {
                float   x   = (float)r.NextDouble() * 1f - 0.5f;
                float   y   = (float)r.NextDouble() * 1f - 0.5f;
                float   z   = (float)r.NextDouble() * 1f - 0.5f;
                Vector3 tmp = Vector3.Transform(color, Matrix4x4.CreateRotationX(x) * Matrix4x4.CreateRotationY(y) * Matrix4x4.CreateRotationZ(z));

                s[i] = ColorUtil.ColorHexString((byte)tmp.X, (byte)tmp.Y, (byte)tmp.Z);

                if (tmp.Length() < lenght)
                {
                    Console.WriteLine(tmp.Length() + "  >  " + lenght);
                    Console.WriteLine(((byte)tmp.X, (byte)tmp.Y, (byte)tmp.Z) + "");
                    Console.WriteLine(x + "  " + y + "  " + z);
                }
            }

            return(s);
        }
Esempio n. 3
0
        public static string[] RandomColors(int quantity)
        {
            Random r = new Random();

            string[] s = new string[quantity];

            for (int i = 0; i < quantity; i++)
            {
                s[i] = ColorUtil.ColorHexString((byte)r.Next(40, 250), (byte)r.Next(40, 250), (byte)r.Next(40, 250));
            }

            return(s);
        }
Esempio n. 4
0
        // Given a number create a color array of that size
        public static string[] GetBackgroundColors(int size)
        {
            string[] colorArray = new string[size];

            Random random = new Random(DateTime.Now.Millisecond);
            int    a, b, c;

            for (int i = 0; i < size; i++)
            {
                a             = random.Next(256);
                b             = random.Next(256);
                c             = random.Next(256);
                colorArray[i] = ColorUtil.ColorHexString((byte)a, (byte)b, (byte)c);
            }

            return(colorArray);
        }
Esempio n. 5
0
        public static string[] GradientColors(int quantity, Vector3 rgbInts)
        {
            string[] s = new string[quantity];

            float   length = rgbInts.Length();
            Vector3 normal = Vector3.Normalize(rgbInts);
            Vector3 tmp;


            for (int i = 0; i < quantity; i++)
            {
                tmp  = normal * length * ((quantity + 2) / (float)(i + 1));
                s[i] = ColorUtil.ColorHexString((byte)tmp.X, (byte)tmp.Y, (byte)tmp.Z);
            }

            return(s);
        }
Esempio n. 6
0
        public static string[] GradientColors(int quantity, int r, int g, int b)
        {
            string[] s = new string[quantity];

            Vector3 rgbInts = new Vector3(r, g, b);

            float   length = rgbInts.Length();
            Vector3 normal = Vector3.Normalize(rgbInts);
            Vector3 tmp;


            for (int i = 0; i < quantity; i++)
            {
                tmp  = rgbInts * (((quantity - i) / (float)(quantity + 2)));
                s[i] = ColorUtil.ColorHexString((byte)tmp.X, (byte)tmp.Y, (byte)tmp.Z);
                Console.WriteLine(s[i]);
            }

            return(s);
        }
        public async static Task <MixedChartConfig> GetMixedChartConfig()
        {
            var weatherService = new OpenWeatherService();

            var forecastData = await weatherService.GetForecastAsync(XamEnvMonitor.Blazor.Constants.City);

            var orderedData = forecastData.ForeCastList.OrderBy(x => x.DateTimeStamp).Take(8).Select(y => new { Date = y.DateText, Temp = y.Main.Temp, MinTemp = y.Main.TempMin, MaxTemp = y.Main.TempMax }).ToList();


            var values        = orderedData.Select(x => x.Temp).ToList();
            var tempValues    = new List <dynamic>();
            var tempMinValues = new List <dynamic>();
            var tempMaxValues = new List <dynamic>();

            foreach (var value in orderedData)
            {
                tempValues.Add(value.Temp);
                tempMinValues.Add(value.MinTemp);
                tempMaxValues.Add(value.MaxTemp);
            }


            var mixedChartConfig = new MixedChartConfig
            {
                CanvasId = "mixedChart",
                Options  = new MixedChartOptions
                {
                    Text       = "Forcasted Temperature History",
                    Display    = true,
                    Responsive = true,
                    Legend     = new Legend
                    {
                        Position = LegendPosition.TOP.ToString(),
                        Reverse  = true,
                        Labels   = new Labels
                        {
                            UsePointStyle = true,
                            BoxWidth      = 85,
                            Padding       = 55,
                            FontSize      = 15,
                            FontColor     = ColorUtil.ColorHexString(205, 205, 205),
                            FontStyle     = "Helvetica"
                        }
                    }
                },
                Data = new MixedChartData
                {
                    Labels   = orderedData.Select(x => x.Date).ToList(),
                    Datasets = new List <IMixableDataset>
                    {
                        new BarChartDataset
                        {
                            Label           = "Forecasted Temperature",
                            BackgroundColor = "#4465fe",
                            BorderColor     = "#4465fe",
                            Data            = tempValues
                        },
                        new LineChartDataset
                        {
                            BackgroundColor  = "#95e086",
                            BorderColor      = "#95e086",
                            Label            = "Minimum Temperature",
                            Data             = tempMinValues,
                            Fill             = true,
                            BorderWidth      = 2,
                            PointRadius      = 3,
                            PointBorderWidth = 1
                        }
                        ,
                        new LineChartDataset
                        {
                            BackgroundColor  = "#ff6384",
                            BorderColor      = "#ff6384",
                            Label            = "Maximum Temperature",
                            Data             = tempMaxValues,
                            Fill             = true,
                            BorderWidth      = 2,
                            PointRadius      = 3,
                            PointBorderWidth = 1
                        }
                    }
                }
            };



            /*         test.Datasets
             *
             *
             *       var mixedChartConfig = new MixedChartConfig()
             *       {
             *           CanvasId = "forcastBarChartCanvas",
             *           Options = new MixedChartOptions()
             *           {
             *               Text = "24 Hour Forecast",
             *               Display = true,
             *               Responsive = true
             *           },
             *           Data = new List<IMixableDataset>
             *           {
             *               new BarChartDataset
             *               {
             *                   Label = "1'st dataset",
             *                   BackgroundColor = "#4465fe",
             *                   BorderColor = "#4465fe",
             *                   Data = new List<object> {19, 12, 5, 3, 3, 2}
             *               },
             *               new LineChartDataset
             *               {
             *                   BackgroundColor = "#ff6384",
             *                   BorderColor = "#ff6384",
             *                   Label = "2'nd dataset",
             *                   Data = new List<object> {19, 12, 5, 3, 3, 2},
             *                   Fill = false,
             *                   BorderWidth = 2,
             *                   PointRadius = 3,
             *                   PointBorderWidth = 1
             *               }
             *               ,
             *               new BarChartDataset
             *               {
             *                   Label = "3'rd dataset",
             *                   BackgroundColor = "#cc65fe",
             *                   BorderColor = "#cc65fe",
             *                   Data = new List<object> {19, 12, 5, 3, 3, 2}
             *               }
             *           }
             *       };
             */
            return(mixedChartConfig);
        }
        protected override async Task OnInitializedAsync()
        {
            barConfig = new BarConfig(ChartType.HorizontalBar)
            {
                Options = new BarOptions
                {
                    Title = new OptionsTitle
                    {
                        Display = false,
                    },
                    Responsive = false,
                    Scales     = new BarScales
                    {
                        XAxes = new List <CartesianAxis>
                        {
                            new LinearCartesianAxis
                            {
                                Ticks = new LinearCartesianTicks
                                {
                                    AutoSkip = false,
                                    Min      = 0,
                                    StepSize = 1
                                },
                            }
                        }
                    },
                    Legend = new Legend
                    {
                        Display = false,
                    }
                }
            };

            var report = await Progress.ExecuteInProgressAsync(() => ReportWebApiClient.GetReportOsobAsync());


            barConfig.Data.Labels.AddRange(report.UcastHracu.Select(item => item.PrijmeniJmeno).ToArray());

            BarDataset <Int32Wrapper> barDataSet = new BarDataset <Int32Wrapper>(ChartType.HorizontalBar)
            {
                BackgroundColor = Enumerable.Range(0, report.UcastHracu.Count).Select(i => ColorUtil.ColorHexString(0, 0, (byte)(255 - (i * 15) % 200))).ToArray()
            };

            barDataSet.AddRange(report.UcastHracu.Select(item => item.PocetTerminu).ToArray().Wrap());
            barConfig.Data.Datasets.Add(barDataSet);

            reportHeight = report.UcastHracu.Count * 40 + 60; // prostě naházeno vidlemi
            isLoaded     = true;
            StateHasChanged();
        }
Esempio n. 9
0
        private void ConfigGraficos()
        {
            gastosPorDia = new PieDataset <double>()
            {
                BackgroundColor = new[]
                {
                    ColorUtil.ColorHexString(255, 99, 132),
                    ColorUtil.ColorHexString(255, 205, 86),
                    ColorUtil.ColorHexString(255, 93, 27),
                    ColorUtil.ColorHexString(150, 27, 196),
                }
            };

            entradasPorDia = new PieDataset <double>()
            {
                BackgroundColor = new[]
                {
                    ColorUtil.ColorHexString(75, 192, 192),
                    ColorUtil.ColorHexString(54, 162, 235)
                }
            };

            total = new PieDataset <double>()
            {
                BackgroundColor = new[]
                {
                    ColorUtil.ColorHexString(192, 0, 0),
                    ColorUtil.ColorHexString(0, 192, 0)
                }
            };

            ConfigEntrada = new PieConfig
            {
                Options = new PieOptions
                {
                    Responsive = true,
                    Title      = new OptionsTitle
                    {
                        Display = true,
                        Text    = "Entradas"
                    }
                }
            };

            ConfigGasto = new PieConfig
            {
                Options = new PieOptions
                {
                    Responsive = true,
                    Title      = new OptionsTitle
                    {
                        Display = true,
                        Text    = "Saídas"
                    }
                }
            };

            ConfigTotal = new PieConfig
            {
                Options = new PieOptions
                {
                    Responsive = true,
                    Title      = new OptionsTitle
                    {
                        Display = true,
                        Text    = "Total"
                    }
                }
            };

            ConfigEntrada.Data.Datasets.Add(entradasPorDia);
            ConfigGasto.Data.Datasets.Add(gastosPorDia);
            ConfigTotal.Data.Datasets.Add(total);
        }