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); }
protected void InitComponent() { options = new PieOptions { Title = new OptionsTitle { Display = false, Text = "" }, Legend = new Legend { Position = Position.Right, Labels = new LegendLabelConfiguration { UsePointStyle = true } }, Responsive = true, Animation = new ArcAnimation { AnimateRotate = true, AnimateScale = true } }; dataset = new PieDataset { BackgroundColor = new[] { ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString() }, BorderWidth = 0, HoverBackgroundColor = ColorUtil.RandomColorString(), HoverBorderColor = ColorUtil.RandomColorString(), HoverBorderWidth = 1, BorderColor = "#ffffff", }; config = new PieConfig(); }
protected override void OnParametersSet() { _config = new PieConfig { Options = new PieOptions { Title = new OptionsTitle { Display = true, Text = "Sample chart from Blazor" }, Responsive = true, Animation = new ArcAnimation { AnimateRotate = true, AnimateScale = true } } }; _config.Data.Labels.AddRange(new[] { "A", "B", "C", "D" }); var pieSet = new PieDataset { BackgroundColor = new[] { ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString() }, BorderWidth = 0, HoverBackgroundColor = ColorUtil.RandomColorString(), HoverBorderColor = ColorUtil.RandomColorString(), HoverBorderWidth = 1, BorderColor = "#ffffff", }; pieSet.Data.AddRange(new double[] { 4, 5, 6, 7 }); _config.Data.Datasets.Add(pieSet); }
private void InitializeCharts() { var activityGroupsByType = UserActivities.GroupBy(a => a.Type); Dictionary <string, int> activityTypesWithCount = activityGroupsByType.ToDictionary(group => group.Key.ToString(), group => group.Count()); Dictionary <string, float> activityTypesWithDistances = activityGroupsByType.ToDictionary(group => group.Key.ToString(), group => group.Sum(a => a.Distance)); Dictionary <string, float> activityTypesWithDuration = activityGroupsByType.ToDictionary(group => group.Key.ToString(), group => group.Sum(a => a.MovingTime)); _distanceChartConfig = ChartService.DrawPieChart("Overall distance by type", new SortedDictionary <string, float>(activityTypesWithDistances)); _countChartConfig = ChartService.DrawPieChart("Activity count by type", new SortedDictionary <string, int>(activityTypesWithCount)); _durationChartConfig = ChartService.DrawPieChart("Overall duration by type", new SortedDictionary <string, float>(activityTypesWithDuration)); }
protected override void OnInitialized() { pieChartComponent = new PieChartComponent(); lineChartComponent = new LineChartComponent(); LastTsStatistics = DateTime.Now.ToString("dddd, dd MMMM yyyy - HH:mm:ss"); LastTsAlerts = DateTime.Now.ToString("dddd, dd MMMM yyyy - HH:mm:ss"); _pieconfig = pieChartComponent.config; _lineConfig = lineChartComponent.config; Twin = new TwinEntity(); Twin.Init(); Alerts = AlertService.GetAlertsAsync(); }
protected override void OnParametersSet() { _config = new PieConfig { Options = new PieOptions { Title = new OptionsTitle { Text = Title, Display = true, FontColor = ColorUtil.FromDrawingColor(Color.White) }, Responsive = true, Animation = new ArcAnimation { AnimateRotate = true, AnimateScale = true }, Legend = new Legend() { Display = false } } }; var pieSet = new PieDataset { BorderWidth = 0, HoverBackgroundColor = ColorUtil.RandomColorString(), HoverBorderColor = ColorUtil.RandomColorString(), HoverBorderWidth = 1, BorderColor = "#ffffff" }; List <string> colors = new List <string>(); for (int i = 0; i < Labels.Count; i++) { colors.Add(ColorUtil.RandomColorString()); } pieSet.BackgroundColor = colors.ToArray(); _config.Data.Labels.AddRange(Labels); pieSet.Data.AddRange(Data); _config.Data.Datasets.Add(pieSet); }
protected void GeneratePieChart(string question, string[] answers, double[] votes) { _q5Config = new PieConfig { Options = new PieOptions { Title = new OptionsTitle { Display = true, Text = question }, Responsive = true, Animation = new ArcAnimation { AnimateRotate = true, AnimateScale = true } } }; _q5Config.Data.Labels.AddRange(answers); var pieSet = new PieDataset { BackgroundColor = answers .Select(i => i == "はい" ? ColorUtil.FromDrawingColor(System.Drawing.Color.Blue) : ColorUtil.FromDrawingColor(System.Drawing.Color.Red)) .ToArray(), BorderWidth = 0, HoverBackgroundColor = answers .Select(i => i.ToString() == "はい" ? ColorUtil.FromDrawingColor(System.Drawing.Color.DarkBlue) : ColorUtil.FromDrawingColor(System.Drawing.Color.DarkRed)) .ToArray(), HoverBorderColor = ColorUtil.FromDrawingColor(System.Drawing.Color.Black), HoverBorderWidth = 1, BorderColor = "#ffffff", }; pieSet.Data.AddRange(votes); _q5Config.Data.Datasets.Add(pieSet); }
public void UpdatePieChartData <T>(Chart chartToUpdate, PieConfig configToUpdate, SortedDictionary <string, T> data) { configToUpdate.Data.Labels.Clear(); configToUpdate.Data.Datasets.Clear(); var values = new T[data.Count]; for (int i = 0; i < data.Count; i++) { var dataElement = data.ElementAt(i); configToUpdate.Data.Labels.Add(dataElement.Key); values[i] = dataElement.Value; } configToUpdate.Data.Datasets.Add(new PieDataset <T>(values) { BackgroundColor = ChartColors.All.Take(data.Count).Select(ColorUtil.FromDrawingColor).ToArray() }); chartToUpdate.Update(); }
public WorldCasesChartConnected() { _chartConfig = new PieConfig { Options = new PieOptions(true) { Legend = new Legend { Display = false }, Responsive = true, MaintainAspectRatio = false, CutoutPercentage = 80, Tooltips = new Tooltips { Enabled = true, Mode = InteractionMode.Index, Intersect = false, BorderWidth = 1, BorderColor = "rgba(0, 0, 0, 0.12)", BackgroundColor = "#ffffff", TitleFontColor = "rgba(0, 0, 0, 0.87)", BodyFontColor = "rgba(0, 0, 0, 0.54)", FooterFontColor = "rgba(0, 0, 0, 0.54)" } } }; _chartDataSet = new PieDataset { BackgroundColor = new[] { "#3f51b5", "#e53935", "#008C00" }, BorderWidth = 8, HoverBorderColor = "#ffffff", BorderColor = "#ffffff" }; _chartConfig.Data.Labels.AddRange(new[] { "Active", "Deaths", "Recovered" }); _chartConfig.Data.Datasets.Add(_chartDataSet); }
public PieConfig DrawPieChart <T>(string title, SortedDictionary <string, T> data) { var config = new PieConfig { Options = new PieOptions { Responsive = true, Title = new OptionsTitle { Display = true, Text = title }, CutoutPercentage = 50, Tooltips = new Tooltips { Enabled = true, }, MaintainAspectRatio = false } }; var values = new T[data.Count]; for (int i = 0; i < data.Count; i++) { var dataElement = data.ElementAt(i); config.Data.Labels.Add(dataElement.Key); values[i] = dataElement.Value; } var dataset = new PieDataset <T>(values) { BackgroundColor = ChartColors.All.Take(data.Count).Select(ColorUtil.FromDrawingColor).ToArray() }; config.Data.Datasets.Add(dataset); return(config); }
protected PieConfig GetChartConfig() { var labels = new List <string>(); var values = new List <double>(); var colours = new List <string>(); foreach (var category in CategoryTimes) { labels.Add(category.Key.Description); values.Add(category.Value); colours.Add(category.Key.Colour); } var config = new PieConfig { Options = new PieOptions { Responsive = true, Animation = new ArcAnimation { AnimateRotate = true, AnimateScale = true, }, CutoutPercentage = 50, OnClick = new DotNetInstanceClickHandler(ClickItem) }, }; config.Data.Labels.AddRange(labels); var dataset = new PieDataset { BackgroundColor = new ChartJs.Blazor.ChartJS.Common.IndexableOption <string>(colours.ToArray()), }; dataset.Data.AddRange(values); config.Data.Datasets.Add(dataset); return(config); }
public static PieConfig SetConfigPieChart(string title, Dictionary <string, double> values) { PieConfig config = new PieConfig() { Options = new PieOptions { Responsive = true, Title = new OptionsTitle { Display = true, Text = title } } }; List <double> items = new List <double>(); List <string> colorsChart = new List <string>(); int i = 0; foreach (string key in values.Keys) { config.Data.Labels.Add(key); items.Add(values[key]); colorsChart.Add(colors[i]); i++; } PieDataset <double> dataset = new PieDataset <double>(items) { BackgroundColor = colors.ToArray() }; config.Data.Datasets.Add(dataset); return(config); }
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); }