private void MapStateToProps(AppState state, WorldByCountryChartProps props) { _barChartConfig.Data.Datasets.Clear(); _barChartConfig.Data.Labels.Clear(); props.ChartConfig = _barChartConfig; var stats = state?.CountriesData; if (stats == null) { return; } var data = stats.ByCountry.OrderByDescending(c => c.Cases).Take(20).ToArray(); _barChartConfig.Data.Labels.AddRange(data.Select(c => c.Country)); var activeDataSet = new BarDataset <Int32Wrapper> { Label = "Active", BackgroundColor = "#3f51b5", BorderColor = ColorUtil.ColorString(0, 0, 0), BorderWidth = 1 }; activeDataSet.AddRange(data.Select(c => c.Active).Wrap()); _barChartConfig.Data.Datasets.Add(activeDataSet); var recoveredDataSet = new BarDataset <Int32Wrapper> { Label = "Recovered", BackgroundColor = "#008C00", BorderColor = ColorUtil.ColorString(0, 0, 0), BorderWidth = 1 }; recoveredDataSet.AddRange(data.Select(c => c.Recovered).Wrap()); _barChartConfig.Data.Datasets.Add(recoveredDataSet); var deathDataSet = new BarDataset <Int32Wrapper> { Label = "Deaths", BackgroundColor = "#e53935", BorderColor = ColorUtil.ColorString(0, 0, 0), BorderWidth = 1 }; deathDataSet.AddRange(data.Select(c => c.Deaths).Wrap()); _barChartConfig.Data.Datasets.Add(deathDataSet); }
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(); }
protected Task GenerateBarChart(string question, string[] answers, double[] votes) { // Note the constructor argument _q1Config = new BarConfig(ChartType.HorizontalBar) { Options = new BarOptions { Title = new OptionsTitle { Display = true, Text = question }, Responsive = true, Scales = new BarScales { XAxes = new List <CartesianAxis> { new LinearCartesianAxis { Ticks = new LinearCartesianTicks { AutoSkip = false, Min = 0 // Otherwise the lowest value in the dataset won't be visible } } } } } }; _q1Config.Data.Labels.AddRange(answers); //Note the constructor argument _q1DataSet = new BarDataset <DoubleWrapper>(ChartType.HorizontalBar) { Label = question, BackgroundColor = Enumerable.Range(0, answers.Length).Select(i => ColorUtil.FromDrawingColor(System.Drawing.Color.BlueViolet)).ToArray(), BorderColor = ColorUtil.FromDrawingColor(System.Drawing.Color.Black), BorderWidth = 1 }; _q1DataSet.AddRange(votes.Wrap()); _q1Config.Data.Datasets.Add(_q1DataSet); return(Task.CompletedTask); }
private void AddBalance() { var barBalanceSet = new BarDataset <Int32Wrapper> { Label = LabelBalances, BackgroundColor = new[] { "#242968", "#218ba5", "#11af66", "#af9d11" }, BorderWidth = 0, HoverBackgroundColor = "#f06384", HoverBorderColor = "#f06384", HoverBorderWidth = 1, BorderColor = "#ffffff", }; barBalanceSet.AddRange(Enumerable.Range(1, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)).Select(i => rnd.Next(30)).Wrap()); barConfig.Data.Datasets.Add(barBalanceSet); }
protected override async Task OnInitializedAsync() { _barChartConfig = new BarConfig { Options = new BarOptions { Legend = { Display = false }, Title = new OptionsTitle { Display = true, Text = "지난 1년동안의 공지사항 글 수" }, Scales = new BarScales { XAxes = new List <CartesianAxis> { new BarCategoryAxis { BarPercentage = 0.5, BarThickness = BarThickness.Flex } }, YAxes = new List <CartesianAxis> { new BarLinearCartesianAxis { Ticks = new LinearCartesianTicks { BeginAtZero = true } } } }, Responsive = true } }; List <string> backgroundColors = new List <string>(); // 배경색: 랜덤 List <string> labels = new List <string>(); // 1월부터 12월까지 List <double> values = new List <double>(); // 1월부터 12월까지의 데이터 for (int i = 1; i <= 12; i++) { labels.Add($"{i}"); backgroundColors.Add(ColorUtil.RandomColorString()); //values.Add(i); } var sortedList = await NoticeRepositoryReference.GetMonthlyCreateCountAsync(); for (int i = 1; i <= 12; i++) { values.Add(sortedList[i]); } _barChartConfig.Data.Labels.AddRange(labels.ToArray()); _barDataSet = new BarDataset <DoubleWrapper> { BackgroundColor = backgroundColors.ToArray(), BorderWidth = 0, HoverBackgroundColor = ColorUtil.RandomColorString(), HoverBorderColor = ColorUtil.RandomColorString(), HoverBorderWidth = 1, BorderColor = "#ffffff" }; _barDataSet.AddRange(values.Wrap()); _barChartConfig.Data.Datasets.Add(_barDataSet); }
protected override void OnInitialized() { _config = new BarConfig { Options = new BarOptions { Legend = new Legend { Display = false }, Responsive = true, MaintainAspectRatio = false, 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)" }, Scales = new BarScales { XAxes = new List <CartesianAxis> { new BarCategoryAxis { BarThickness = 12, MaxBarThickness = 10, BarPercentage = 0.5, CategoryPercentage = 0.5, // Ticks = new CategoryTicks // { // FontColor = "rgba(0, 0, 0, 0.54)" // }, GridLines = new GridLines { Display = false, DrawBorder = false, OffsetGridLines = true }, Offset = true, OffsetGridLines = true } }, YAxes = new List <CartesianAxis> { new BarLinearCartesianAxis { BarThickness = 12, MaxBarThickness = 10, BarPercentage = 0.5, CategoryPercentage = 0.5, Ticks = new LinearCartesianTicks { BeginAtZero = true, Min = 0 // FontColor = "rgba(0, 0, 0, 0.54)" }, GridLines = new GridLines { BorderDash = new double [] { 2 }, DrawBorder = false, Color = "rgba(0, 0, 0, 0.12)", ZeroLineBorderDash = new int [] { 2 }, ZeroLineBorderDashOffset = 2, ZeroLineColor = "rgba(0, 0, 0, 0.12)" } } } } } }; _config.Data.Labels.AddRange(new[] { "1 Aug", "2 Aug", "3 Aug", "4 Aug", "5 Aug", "6 Aug" }); var barSet1 = new BarDataset <DoubleWrapper> { Label = "This year", BackgroundColor = "#3f51b5" }; barSet1.AddRange(new DoubleWrapper[] { 18, 5, 19, 27, 29, 19 }); var barSet2 = new BarDataset <DoubleWrapper> { Label = "Last year", BackgroundColor = "#e5e5e5" }; barSet2.AddRange(new DoubleWrapper[] { 11, 20, 12, 29, 30, 25 }); _config.Data.Datasets.AddRange(new[] { barSet1, barSet2 }); }