public static ConfigBase GetChartConfig(DsResponse response) { var config = GetBarConfig(); config.Options.Title.Text = response.Interest; List <double> pointData = new List <double>(); foreach (var item in response.Items) { config.Data.Labels.Add(item.Label); pointData.Add(item.Count == 0 ? 0 : Math.Round((double)item.Wins * 100.0 / (double)item.Count, 2)); } var pointDataset = new BarDataset <double>(pointData) { Label = "global", BorderColor = DSData.CMDRcolor[response.Interest], BorderWidth = 2, }; config.Data.Datasets.Add(pointDataset); return(config); }
public static Chart BuildColorfulBarChart(List <string> labels, List <double?> counts) { Chart chart = new Chart(); chart.Type = Enums.ChartType.Bar; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); data.Labels = labels; BarDataset dataset = new BarDataset() { Data = counts, BackgroundColor = new List <ChartColor> { Colors.GetRed(), Colors.GetOrange(), Colors.GetYellow(), Colors.GetGreen(), Colors.GetBlue(), Colors.GetPurple(), Colors.GetRed(), Colors.GetOrange(), Colors.GetYellow(), Colors.GetGreen(), Colors.GetBlue(), Colors.GetPurple() }, BorderColor = new List <ChartColor> { Colors.GetRedBorder(), Colors.GetOrangeBorder(), Colors.GetYellowBorder(), Colors.GetGreenBorder(), Colors.GetBlueBorder(), Colors.GetPurpleBorder(), Colors.GetRedBorder(), Colors.GetOrangeBorder(), Colors.GetYellowBorder(), Colors.GetGreenBorder(), Colors.GetBlueBorder(), Colors.GetPurpleBorder() }, BorderWidth = new List <int> { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, }; data.Datasets = new List <Dataset>(); data.Datasets.Add(dataset); chart.Data = data; chart.Options = BeginsAtZeroOptions(); DisableLabel(chart.Options); return(chart); }
GetDataSetsConverter() { Func <DateTime?, DateTime?, DateRangeGranulation?, Task <IEnumerable <IDataset> > > fnc = async(fromDate, toDate, granulation) => { var data = await LoadData(fromDate, toDate, granulation); var lineDataSets = new List <LineDataset <TimePoint> > { new() { Label = "Average water flow", BackgroundColor = ColorUtil.FromDrawingColor(Color.Green), BorderColor = ColorUtil.FromDrawingColor(Color.Green), Fill = FillingMode.Disabled }, new() { Label = "Maximum water flow", BackgroundColor = ColorUtil.FromDrawingColor(Color.Red), BorderColor = ColorUtil.FromDrawingColor(Color.Red), Fill = FillingMode.Disabled }, new() { Label = "Minimum water flow", BackgroundColor = ColorUtil.FromDrawingColor(Color.Blue), BorderColor = ColorUtil.FromDrawingColor(Color.Blue), Fill = FillingMode.Disabled } }; var barDataSet = new BarDataset <TimePoint> { Label = "Total water volume", BackgroundColor = ColorUtil.FromDrawingColor(Color.Orange), BorderColor = ColorUtil.FromDrawingColor(Color.Orange), YAxisId = TOTAL_WATER_VOLUME_Y_AXIS_ID }; foreach (var irrigationDataVm in data) { lineDataSets[0] .Add(new TimePoint(irrigationDataVm.Timestamp, irrigationDataVm.AverageWaterFlow)); lineDataSets[1].Add(new TimePoint(irrigationDataVm.Timestamp, irrigationDataVm.MaxWaterFlow)); lineDataSets[2].Add(new TimePoint(irrigationDataVm.Timestamp, irrigationDataVm.MinWaterFlow)); barDataSet.Add(new TimePoint(irrigationDataVm.Timestamp, irrigationDataVm.TotalWaterVolume)); } return(lineDataSets.Select(x => x as IDataset).Append(barDataSet)); }; return(fnc); }
public async Task <Chart> GenerateBasicExpensesChart(string userId) { var toDisplay = await GetAmountPerCategory(TimePeriod.Month, userId); var amountperCategory = new List <double?>(); var chart = new Chart { Type = Enums.ChartType.Bar }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); data.Labels = new List <string>(); foreach (var item in toDisplay) { data.Labels.Add(item.Category.CategoryName); amountperCategory.Add(decimal.ToDouble(item.Amount)); } var dataset = new BarDataset { Label = "Expenses per Category", Data = amountperCategory, BackgroundColor = new List <ChartColor> { ChartColor.FromRgba(255, 99, 132, 1), }, }; data.Datasets = new List <Dataset> { dataset }; chart.Data = data; chart.Options = await GetOptions(); chart.Options.Layout = new Layout { Padding = new Padding { PaddingObject = new PaddingObject { Left = 10, Right = 12, Top = 10, Bottom = 10 } } }; return(chart); }
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(); }
private static Chart GetWeekDailyWatchedChart(Dictionary <string, double> timePerWeekday) { var chart = new Chart { Type = Enums.ChartType.Bar }; var data = new ChartJSCore.Models.Data { Labels = timePerWeekday.Keys.ToList() }; var dataset = new BarDataset { Label = "# hours watched", Data = new List <double?>(timePerWeekday.Values.Select(x => (double?)x)), BorderWidth = new List <int> { 1 }, BackgroundColor = new List <ChartColor> { ChartColor.FromRgba(229, 9, 20, 0.8) }, Type = Enums.ChartType.Bar, }; data.Datasets = new List <Dataset> { dataset }; chart.Data = data; chart.Options = new Options { Responsive = true, MaintainAspectRatio = false, Title = new Title { Text = "Hours watched per weekday", Display = true }, ResponsiveAnimationDuration = 500, Scales = new Scales { YAxes = new List <Scale> { new CartesianScale { Ticks = new CartesianLinearTick { BeginAtZero = true } } } } }; return(chart); }
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 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); }
public static Chart BuildColorfulBarChartWithManyDatasets(List <string> labels, List <List <double?> > counts, List <string> datasetLabels) { Chart chart = new Chart(); chart.Type = Enums.ChartType.Bar; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); data.Labels = labels; data.Datasets = new List <Dataset>(); var backgroundColors = new List <ChartColor> { Colors.GetRed(), Colors.GetBlue(), Colors.GetGreen() }; var borderColors = new List <ChartColor> { Colors.GetRedBorder(), Colors.GetBlueBorder(), Colors.GetGreenBorder() }; for (int i = 0; i < counts.Count; i++) { BarDataset dataset = new BarDataset() { Label = datasetLabels[i], Data = counts[i], BackgroundColor = new List <ChartColor> { backgroundColors[i] }, BorderColor = new List <ChartColor> { borderColors[i] }, BorderWidth = new List <int> { 1 }, }; data.Datasets.Add(dataset); } chart.Options = BeginsAtZeroOptions(); chart.Data = data; return(chart); }
private async Task TaskLoadRepartition() { var getStatistics = await httpClient.GetAsync($"api/ads/repartition/{Id}"); getStatistics.EnsureSuccessStatusCode(); var jStatistics = await getStatistics.Content.ReadAsStringAsync(); var statistics = JsonConvert.DeserializeObject <List <StatisticKeyPoint> >(jStatistics); foreach (var date in statistics.Select(s => s.Date.ToString("dd/MM")).Distinct().ToArray()) { _config.Data.Labels.Add(date); } var socialNetworks = statistics.Where(s => s.Key != "Total" && s.Key != "Direct").Select(s => s.Key).ToList(); foreach (var socialNetwork in socialNetworks) { if (statistics.Any(d => d.Key == socialNetwork) == false) { continue; } var dataset1 = new BarDataset <int>(statistics.Where(s => s.Key == socialNetwork).OrderBy(s => s.Date).Select(s => s.Value).ToArray()) { Label = socialNetwork, BorderWidth = 1 }; _config.Data.Datasets.Add(dataset1); } var dataSetdirect = new BarDataset <int>(statistics.Where(s => s.Key == "Direct").OrderBy(s => s.Date).Select(s => s.Value).ToArray()) { Label = Loc["Direct"], BackgroundColor = ColorUtil.FromDrawingColor(Color.Green), BorderWidth = 1 }; _repartitionConfig.Data.Datasets.Add(dataSetdirect); await _chartRepartition.Update(); }
private BarDataset GetCapacityForMachineGroupById(int machineGroupId, int minRange, int maxRange, int state, List <SimulationWorkschedule> simulationWorkschedule) { var productionOrderWorkSchedulesBy = simulationWorkschedule.Where(x => x.Machine == machineGroupId.ToString()); var data = new List <double>(); for (var i = minRange; i < maxRange; i++) { int item; switch (state) { case 1: item = productionOrderWorkSchedulesBy.Where(x => x.SimulationType == SimulationType.BackwardPlanning).Count(x => x.Start <= i && x.End > i); break; case 2: item = productionOrderWorkSchedulesBy.Where(x => x.SimulationType == SimulationType.ForwardPlanning).Count(x => x.Start <= i && x.End > i); break; default: item = productionOrderWorkSchedulesBy.Where(x => x.SimulationType == SimulationType.Central).Count(x => x.Start <= i && x.End > i); break; } data.Add(item); } var dataset = new BarDataset() { Label = "MachineGroup " + machineGroupId.ToString(), BackgroundColor = new List <string> { new ChartColor().Color[machineGroupId - 1] }, Data = data, }; return(dataset); }
private static Chart GetTimePerSerieChart(Dictionary <string, double> timePerSerie) { var chart = new Chart { Type = Enums.ChartType.HorizontalBar }; var data = new ChartJSCore.Models.Data { Labels = timePerSerie.Keys.ToList() }; var dataset = new BarDataset { Label = "# hours watched", Data = new List <double?>(timePerSerie.Values.Select(x => (double?)x)), BorderWidth = new List <int> { 1 }, BackgroundColor = new List <ChartColor> { ChartColor.FromRgba(229, 9, 20, 0.8) }, Type = Enums.ChartType.HorizontalBar }; data.Datasets = new List <Dataset> { dataset }; chart.Data = data; chart.Options = new Options { Responsive = true, MaintainAspectRatio = false, Title = new Title { Text = "Hours watched per serie", Display = true }, ResponsiveAnimationDuration = 500 }; return(chart); }
private async Task GenerateBarChart() { Config.Data.Labels.Clear(); Config.Data.Datasets.Clear(); IDataset <int> expenseDataSet = new BarDataset <int>() { Label = "Expenses", BackgroundColor = ColorUtil.FromDrawingColor(Color.FromArgb(128, Color.Red)), BorderColor = ColorUtil.FromDrawingColor(Color.Red), BorderWidth = 1 }; IDataset <int> incomeDataSet = new BarDataset <int>() { Label = "Incomes", BackgroundColor = ColorUtil.FromDrawingColor(Color.FromArgb(128, Color.Green)), BorderColor = ColorUtil.FromDrawingColor(Color.Green), BorderWidth = 1 }; for (int i = 0; i < Constants.MonthsInYear; i++) { int expenseAmount = (int)Expenses.Where(e => e.DateTime.Month == i).Sum(e => e.Amount); expenseDataSet.Add(expenseAmount); int incomeAmount = (int)Incomes.Where(e => e.DateTime.Month == i).Sum(e => e.Amount); incomeDataSet.Add(incomeAmount); } ((List <string>)Config.Data.Labels).AddRange(Constants.Months); Config.Data.Datasets.Add(expenseDataSet); Config.Data.Datasets.Add(incomeDataSet); await Chart.Update(); }
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); }
public Chart CreateBarChart(TfsQueryResult queryResult) { Chart chart = new Chart { Type = "bar" }; Data data = new Data { Labels = new List <string>() }; var counts = queryResult .TfsItems .GroupBy(t => t.TransitionCount) .OrderBy(t => t.Key) .Select(c => c.Key) .ToList(); var rawData = new List <double>(); foreach (var count in counts) { data.Labels.Add($"{"cycle".ToQuantity(count)}"); var itemCount = queryResult.TfsItems.Count(t => t.TransitionCount == count); rawData.Add(itemCount); } BarDataset dataset = new BarDataset() { Label = "# work items with cycle", Data = rawData, BackgroundColor = new List <string>() { "rgba(255, 99, 132, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(255, 206, 86, 0.2)", "rgba(75, 192, 192, 0.2)", "rgba(153, 102, 255, 0.2)", "rgba(255, 159, 64, 0.2)" }, BorderColor = new List <string>() { "rgba(255,99,132,1)", "rgba(54, 162, 235, 1)", "rgba(255, 206, 86, 1)", "rgba(75, 192, 192, 1)", "rgba(153, 102, 255, 1)", "rgba(255, 159, 64, 1)" }, BorderWidth = new List <int>() { 1 }, }; data.Datasets = new List <Dataset> { dataset }; chart.Data = data; BarOptions options = new BarOptions() { Scales = new Scales(), BarPercentage = 0.7, Title = new Title { Display = true, Text = "Frequency of Cycles (transitions)" }, }; Scales scales = new Scales() { YAxes = new List <Scale>() { new CartesianScale() { Ticks = new CartesianLinearTick() { BeginAtZero = true } } } }; options.Scales = scales; chart.Options = options; chart.Options.Layout = new Layout() { Padding = new Padding() { PaddingObject = new PaddingObject() { Left = 10, Right = 12 } } }; return(chart); }
public async Task <IViewComponentResult> InvokeAsync(List <string> paramsList) { SimulationType simType = (paramsList[index : 1].Equals(value : "Decentral")) ? SimulationType.Decentral : SimulationType.Central; var kpis = _context.Kpis.Where(predicate: x => x.KpiType == KpiType.LayTime && x.SimulationConfigurationId == Convert.ToInt32(paramsList[0]) && x.SimulationType == simType && x.SimulationNumber == Convert.ToInt32(paramsList[2]) && x.IsKpi == true).OrderBy(keySelector: x => x.Name).ToList(); var maxVal = _context.Kpis.Where(predicate: x => x.KpiType == KpiType.LayTime && x.SimulationConfigurationId == Convert.ToInt32(paramsList[0]) && x.SimulationNumber == Convert.ToInt32(paramsList[2]) && x.IsKpi == true).Max(selector: x => x.ValueMax); maxVal = Math.Ceiling(a: maxVal / 100) * 100; var generateChartTask = Task.Run(function: () => { if (!_context.SimulationOperations.Any()) { return(null); } Chart chart = new Chart(); var lables = new List <string>(); var cc = new ChartColors(); // charttype chart.Type = Enums.ChartType.HorizontalBar; var data = new Data { Datasets = new List <Dataset>() }; var min = new BarDataset { Type = Enums.ChartType.HorizontalBar, Data = new List <double>(), BackgroundColor = new List <ChartColor>() // { cc.Color[8], cc.Color[4], cc.Color[1] } }; var avg = new BarDataset { Type = Enums.ChartType.HorizontalBar, Data = new List <double>(), BackgroundColor = new List <ChartColor>() // { cc.Color[8], , cc.Color[1] } }; var max = new BarDataset { Type = Enums.ChartType.HorizontalBar, Data = new List <double>(), BackgroundColor = new List <ChartColor>() // { cc.Color[8], cc.Color[4], cc.Color[1] } }; foreach (var kpi in kpis) { lables.Add(item: kpi.Name); min.Data.Add(item: kpi.ValueMin); avg.Data.Add(item: kpi.Value - kpi.ValueMin); max.Data.Add(item: kpi.ValueMax - kpi.Value); min.BackgroundColor.Add(item: ChartColors.Transparent); avg.BackgroundColor.Add(item: cc.Color[index: 4]); max.BackgroundColor.Add(item: cc.Color[index: 1]); } data.Datasets.Add(item: min); data.Datasets.Add(item: avg); data.Datasets.Add(item: max); data.Labels = lables; var xAxis = new List <Scale>() { new CartesianScale { Stacked = true, Display = true, Ticks = new CartesianLinearTick { Max = Convert.ToInt32(value: maxVal), Display = true }, Id = "first-x-axis", Type = "linear", ScaleLabel = new ScaleLabel { LabelString = "Time in min", Display = true, FontSize = 12 } }, }; var yAxis = new List <Scale>() { new CartesianScale { Stacked = true, Display = true } }; // Ticks = new Tick { BeginAtZero = true, Min = 0, Max = 100 } //var yAxis = new List<Scale>() { new BarScale{ Ticks = new CategoryTick { Min = "0", Max = (yMaxScale * 1.1).ToString() } } }; chart.Options = new Options() { Scales = new Scales { XAxes = xAxis, YAxes = yAxis }, MaintainAspectRatio = false, Responsive = true, Legend = new Legend { Display = false } }; chart.Data = data; return(chart); }); // create JS to Render Chart. ViewData[index : "chart"] = await generateChartTask; ViewData[index : "Type"] = paramsList[index : 1]; ViewData[index : "Data"] = kpis.ToList(); return(View(viewName: $"IdlePeriod")); }
protected override void OnInitialized() { _config = new BarConfig { Options = new BarOptions { Responsive = true, Title = new OptionsTitle { Display = true, Text = "Chart.js Bar Chart - Stacked" }, //Tooltips = new Tooltips //{ // Mode = InteractionMode.Index, // Intersect = false //}, Scales = new BarScales { XAxes = new List <CartesianAxis> { new BarCategoryAxis { Stacked = true } }, YAxes = new List <CartesianAxis> { new BarLinearCartesianAxis { Stacked = true } } } } }; //BarDataset<BlazorTrader.Data.TimeSales_Content> dataset1 = new BarDataset<BlazorTrader.Data.TimeSales_Content>(); //BarDataset<BlazorTrader.Data.TimeSales_Content> dataset2 = new BarDataset<BlazorTrader.Data.TimeSales_Content>(); //BarDataset<BlazorTrader.Data.TimeSales_Content> dataset3 = new BarDataset<BlazorTrader.Data.TimeSales_Content>(); //BarDataset<BlazorTrader.Data.TimeSales_Content> dataset4 = new BarDataset<BlazorTrader.Data.TimeSales_Content>(); BarDataset <List <BarData> > dataset1 = new BarDataset <List <BarData> >() { Label = "Dataset 1", BackgroundColor = ColorUtil.FromDrawingColor(SampleUtils.ChartColors.Red) }; BarDataset <List <BarData> > dataset2 = new BarDataset <List <BarData> >() { Label = "Dataset 2", BackgroundColor = ColorUtil.FromDrawingColor(SampleUtils.ChartColors.Blue) }; BarDataset <List <BarData> > dataset3 = new BarDataset <List <BarData> >() { Label = "Dataset 3", BackgroundColor = ColorUtil.FromDrawingColor(SampleUtils.ChartColors.Green) }; _config.Data.Labels.AddRange(SampleUtils.Months); _config.Data.Datasets.Add(dataset1); _config.Data.Datasets.Add(dataset2); _config.Data.Datasets.Add(dataset3); }
private static Chart GenerateBarChart() { var chart = new Chart { Type = Enums.ChartType.Bar }; var data = new Data { Labels = new List <string> { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" } }; var dataset = new BarDataset { Label = "# of Votes", Data = new List <double> { 12, 19, 3, 5, 2, 3 }, BackgroundColor = new List <ChartColor> { ChartColor.FromRgba(255, 99, 132, 0.2), ChartColor.FromRgba(54, 162, 235, 0.2), ChartColor.FromRgba(255, 206, 86, 0.2), ChartColor.FromRgba(75, 192, 192, 0.2), ChartColor.FromRgba(153, 102, 255, 0.2), ChartColor.FromRgba(255, 159, 64, 0.2) }, BorderColor = new List <ChartColor> { ChartColor.FromRgb(255, 99, 132), ChartColor.FromRgb(54, 162, 235), ChartColor.FromRgb(255, 206, 86), ChartColor.FromRgb(75, 192, 192), ChartColor.FromRgb(153, 102, 255), ChartColor.FromRgb(255, 159, 64) }, BorderWidth = new List <int> { 1 } }; data.Datasets = new List <Dataset> { dataset }; chart.Data = data; var options = new BarOptions { Scales = new Scales(), BarPercentage = 0.7 }; var scales = new Scales { YAxes = new List <Scale> { new CartesianScale { Ticks = new CartesianLinearTick { BeginAtZero = true } } } }; options.Scales = scales; chart.Options = options; chart.Options.Layout = new Layout { Padding = new Padding { PaddingObject = new PaddingObject { Left = 10, Right = 12 } } }; return(chart); }
/// <summary> /// Returns a Bar Chart configuration tailored for OEE Reporting /// </summary> /// <param name="machineNo"></param> /// <param name="timeSpan"></param> /// <returns></returns> public static Chart GetBarChart(IEnumerable <BarChartValue> data, string title, string scaleLabel, SortType sortType = SortType.None, bool displayLegend = true) { // Format the chart itself var titleFontSize = 12; try { titleFontSize = int.Parse(SystemHelper.GetConfigValue("AppSettings:TitleFontSize")); } catch { } var chart = new Chart(); chart.Type = Enums.ChartType.Bar; chart.Options = new Options() { Responsive = true, Title = new Title() { Display = !string.IsNullOrEmpty(title), Text = title, FontSize = titleFontSize }, Legend = new Legend() { Display = displayLegend } }; // Specify the Chart Object to use chart.Data = new ChartJSCore.Models.Data(); chart.Data.Datasets = new List <Dataset>(); var allSeries = data.Select(x => x.Group).Distinct().ToList(); chart.Data.Labels = allSeries; // Sort the data based on user request IDictionary <string, double?> sortedData; switch (sortType) { case SortType.None: sortedData = data.ToDictionary(x => x.Label, y => y.Value); break; case SortType.ByLabel: sortedData = data.OrderBy(a => a.Label).ToDictionary(x => x.Label, y => y.Value); break; case SortType.ByLabelDescending: sortedData = data.OrderByDescending(a => a.Label).ToDictionary(x => x.Label, y => y.Value); break; case SortType.ByValue: sortedData = data.OrderBy(a => a.Value).ToDictionary(x => x.Label, y => y.Value); break; case SortType.ByValueDescending: sortedData = data.OrderByDescending(a => a.Value).ToDictionary(x => x.Label, y => y.Value); break; default: sortedData = data.ToDictionary(x => x.Label, y => y.Value); break; } var labels = sortedData.Select(x => x.Key).ToList(); var i = 0; foreach (var label in labels) { var dataSet = new BarDataset() { Label = label, Data = new List <double?> { sortedData[label] }, BackgroundColor = new List <ChartColor>() { ChartColor.FromHexString(_colorList[i % _colorList.Count]) }, BorderColor = new List <ChartColor>() { ChartColor.FromHexString("#000000") } }; chart.Data.Datasets.Add(dataSet); i++; } // Return the chart to the caller return(chart); }
/// <summary> /// 1st = Param[0] = SimulationId /// 2st = Param[1] = SimulationType /// 3nd = Param[2] = SimulationNumber /// </summary> /// <param name="paramsList"></param> /// <returns></returns> public async Task <IViewComponentResult> InvokeAsync(List <string> paramsList) { // Determine Type and Data _simList.Add(new Tuple <int, SimulationType>(Convert.ToInt32(paramsList[0]), (paramsList[1] == "Central") ? SimulationType.Central : SimulationType.Decentral)); if (paramsList.Count() == 8) { _simList.Add(new Tuple <int, SimulationType>(Convert.ToInt32(paramsList[6]), (paramsList[7] == "Central") ? SimulationType.Central : SimulationType.Decentral)); } if (paramsList.Count() >= 6) { _simList.Add(new Tuple <int, SimulationType>(Convert.ToInt32(paramsList[4]), (paramsList[5] == "Central") ? SimulationType.Central : SimulationType.Decentral)); } if (paramsList.Count() >= 4) { _simList.Add(new Tuple <int, SimulationType>(Convert.ToInt32(paramsList[2]), (paramsList[3] == "Central") ? SimulationType.Central : SimulationType.Decentral)); } var kpi = new List <Kpi>(); // charttype foreach (var sim in _simList) { var trick17 = _context.Kpis.Where(x => x.KpiType == KpiType.LeadTime && x.SimulationConfigurationId == sim.Item1 && x.SimulationNumber == 1 && x.SimulationType == sim.Item2); kpi.AddRange(trick17.ToList()); } var max = kpi.Max(m => m.Value); var generateChartTask = Task.Run(() => { if (!_context.SimulationWorkschedules.Any()) { return(null); } Chart chart = new Chart(); // charttype chart.Type = "bar"; // use available hight in Chart chart.Options = new Options() { MaintainAspectRatio = false, Responsive = true, Legend = new Legend { Position = "bottom", Display = false }, Title = new Title { Text = "BoxPlot LeadTimes", Position = "top", FontSize = 24, FontStyle = "bold", Display = true }, Scales = new Scales { YAxes = new List <Scale> { new CartesianScale { Stacked = true, Display = true, Ticks = new CartesianLinearTick { Max = ((int)Math.Ceiling(max / 100.0)) * 100 } } }, XAxes = new List <Scale> { new CartesianScale { Stacked = true, Display = true } }, }, Tooltips = new ToolTip { Mode = "x", Callbacks = new Callback { Label = BoxplotCallback() } } }; var labels = kpi.Select(n => n.Name).Distinct().ToList(); var data = new Data { Datasets = new List <Dataset>(), Labels = labels, }; var dsClear = new BarDataset { Data = new List <double>(), Label = "dsClear", BackgroundColor = new List <string>(), BorderWidth = new List <int>(), BorderColor = new List <string>() }; var lowerStroke = new BarDataset { Data = new List <double>(), Label = "lowerStroke", BackgroundColor = new List <string>(), BorderWidth = new List <int>(), BorderColor = new List <string>() }; var firstQuartile = new BarDataset { Data = new List <double>(), Label = "fQ", BackgroundColor = new List <string>(), BorderWidth = new List <int>(), BorderColor = new List <string>() }; var secondQuartile = new BarDataset { Data = new List <double>(), Label = "Med", BackgroundColor = new List <string>(), BorderWidth = new List <int>(), BorderColor = new List <string>() }; var thirdQuartile = new BarDataset { Data = new List <double>(), Label = "uQ", BackgroundColor = new List <string>(), BorderWidth = new List <int>(), BorderColor = new List <string>() }; var fourthQuartile = new BarDataset { Data = new List <double>(), Label = "line", BackgroundColor = new List <string>(), BorderWidth = new List <int>(), BorderColor = new List <string>() }; var upperStroke = new BarDataset { Data = new List <double>(), Label = "upperStroke", BackgroundColor = new List <string>(), BorderWidth = new List <int>(), BorderColor = new List <string>() }; var products = kpi.Select(x => x.Name).Distinct().ToList(); var colors = new ChartColor(); int i = 0; foreach (var sim in _simList) { foreach (var product in products) { var boxplotValues = kpi.Where(x => x.IsKpi == false && x.Name == product && x.SimulationConfigurationId == sim.Item1 && x.SimulationType == sim.Item2).OrderBy(x => x.Value) .ToList(); dsClear.Data.Add((double)boxplotValues.ElementAt(0).Value); dsClear.BackgroundColor.Add(ChartColor.Transparent); dsClear.BorderColor.Add(ChartColor.Transparent); dsClear.BorderWidth.Add(0); lowerStroke.Data.Add(5); lowerStroke.BackgroundColor.Add(ChartColor.Transparent); lowerStroke.BorderColor.Add("rgba(50, 50, 50, 1)"); lowerStroke.BorderWidth.Add(2); var fq = (double)(boxplotValues.ElementAt(1).Value - boxplotValues.ElementAt(0).Value - 5); firstQuartile.Data.Add(fq); firstQuartile.BackgroundColor.Add("rgba(50, 50, 50, 1)");// .Add(colors.Color[i].Substring(0, colors.Color[i].Length - 4) + "0.8)"); firstQuartile.BorderColor.Add("rgba(50, 50, 50, 1)"); firstQuartile.BorderWidth.Add(0); var m = (double)(boxplotValues.ElementAt(2).Value - boxplotValues.ElementAt(1).Value); secondQuartile.Data.Add(m); secondQuartile.BackgroundColor.Add(colors.Color[i].Substring(0, colors.Color[i].Length - 4) + "0.8)"); secondQuartile.BorderColor.Add("rgba(50, 50, 50, 1)"); secondQuartile.BorderWidth.Add(1); var up = (double)(boxplotValues.ElementAt(3).Value - boxplotValues.ElementAt(2).Value); thirdQuartile.Data.Add(up); thirdQuartile.BackgroundColor.Add(colors.Color[i].Substring(0, colors.Color[i].Length - 4) + "0.8)"); thirdQuartile.BorderColor.Add("rgba(50, 50, 50, 1)"); thirdQuartile.BorderWidth.Add(1); var hs = (double)(boxplotValues.ElementAt(4).Value - boxplotValues.ElementAt(3).Value - 5); fourthQuartile.Data.Add(hs); fourthQuartile.BackgroundColor.Add("rgba(50, 50, 50, 1)"); //.Add(colors.Color[i].Substring(0, colors.Color[i].Length - 4) + "0.8)"); fourthQuartile.BorderColor.Add("rgba(50, 50, 50, 1)"); fourthQuartile.BorderWidth.Add(0); upperStroke.Data.Add(5); upperStroke.BackgroundColor.Add(ChartColor.Transparent); upperStroke.BorderColor.Add("rgba(50, 50, 50, 1)"); upperStroke.BorderWidth.Add(2); i = i + 2; } } data.Datasets.Add(dsClear); data.Datasets.Add(lowerStroke); data.Datasets.Add(firstQuartile); data.Datasets.Add(secondQuartile); data.Datasets.Add(thirdQuartile); data.Datasets.Add(fourthQuartile); data.Datasets.Add(upperStroke); var avg = kpi.Sum(x => x.Value) / kpi.Count(); var min = kpi.Min(x => x.Value); var end = ((int)Math.Ceiling(max / 100.0)) * 100; //data.Datasets[0].Data = new List<double> { 0, (int)(min/end*100), (int)(avg /end*100), (int)(max /end*100), end }; //data.Datasets[0].Data = new List<double> { min, avg, 10, max, end-max }; chart.Data = data; return(chart); }); // create JS to Render Chart. ViewData["chart"] = await generateChartTask; ViewData["Type"] = paramsList[1]; ViewData["Data"] = kpi.Where(w => w.IsFinal && w.IsKpi).ToList(); ViewData["percentage"] = Math.Round(kpi.Sum(x => x.Value) / kpi.Count(), 0); return(View($"ProductLeadTime")); }
private Task <Chart> GenerateChartTask(List <string> paramsList) { var generateChartTask = Task.Run(function: () => { if (!_resultContext.SimulationJobs.Any()) { return(null); } SimulationType simType = (paramsList[index: 1].Equals(value: "Decentral")) ? SimulationType.Decentral : SimulationType.Central; Chart chart = new Chart { Type = Enums.ChartType.Bar }; // charttype // use available hight in Chart // use available hight in Chart var machines = _resultContext.Kpis.Where(predicate: x => x.SimulationConfigurationId == Convert.ToInt32(paramsList[0]) && x.SimulationType == simType && x.KpiType == KpiType.ResourceUtilization && x.IsKpi && x.IsFinal && x.SimulationNumber == Convert.ToInt32(paramsList[2])) .OrderByDescending(keySelector: g => g.Name) .ToList(); var data = new Data { Labels = machines.Select(selector: n => n.Name).ToList() }; // create Dataset for each Lable data.Datasets = new List <Dataset>(); var i = 0; var cc = new ChartColors(); //var max = _context.SimulationWorkschedules.Max(x => x.End) - 1440; var barDataSet = new BarDataset { Data = new List <double?>(), BackgroundColor = new List <ChartColor>(), HoverBackgroundColor = new List <ChartColor>(), YAxisID = "y-normal" }; var barDiversityInvisSet = new BarDataset { Data = new List <double?>(), BackgroundColor = new List <ChartColor>(), HoverBackgroundColor = new List <ChartColor>(), YAxisID = "y-diversity" }; var barDiversitySet = new BarDataset { Data = new List <double?>(), BackgroundColor = new List <ChartColor>(), HoverBackgroundColor = new List <ChartColor>(), YAxisID = "y-diversity" }; foreach (var machine in machines) { var percent = Math.Round(value: machine.Value * 100, digits: 2); // var wait = max - work; barDataSet.Data.Add(item: percent); barDataSet.BackgroundColor.Add(item: cc.Get(i, 0.4)); barDataSet.HoverBackgroundColor.Add(item: cc.Get(i, 0.7)); var varianz = machine.Count * 100; barDiversityInvisSet.Data.Add(item: percent - Math.Round(value: varianz / 2, digits: 2)); barDiversityInvisSet.BackgroundColor.Add(item: ChartColors.Transparent); barDiversityInvisSet.HoverBackgroundColor.Add(item: ChartColors.Transparent); barDiversitySet.Data.Add(item: Math.Round(value: varianz, digits: 2)); barDiversitySet.BackgroundColor.Add(item: cc.Get(i, 0.8)); barDiversitySet.HoverBackgroundColor.Add(item: cc.Get(i, 1)); i++; } data.Datasets.Add(item: barDataSet); data.Datasets.Add(item: barDiversityInvisSet); data.Datasets.Add(item: barDiversitySet); chart.Data = data; // Specifie xy Axis var xAxis = new List <Scale>() { new CartesianScale { Stacked = true, Id = "x-normal", Display = true } }; var yAxis = new List <Scale>() { new CartesianScale { Stacked = true, Display = true, Ticks = new CartesianLinearTick { BeginAtZero = true, Min = 0, Max = 100 }, Id = "y-normal" }, new CartesianScale { Stacked = true, Ticks = new CartesianLinearTick { BeginAtZero = true, Min = 0, Max = 100 }, Display = false, Id = "y-diversity", ScaleLabel = new ScaleLabel { LabelString = "Value in %", Display = false, FontSize = 12 }, }, }; //var yAxis = new List<Scale>() { new BarScale{ Ticks = new CategoryTick { Min = "0", Max = (yMaxScale * 1.1).ToString() } } }; chart.Options = new Options() { Scales = new Scales { XAxes = xAxis, YAxes = yAxis }, MaintainAspectRatio = false, Responsive = true, Title = new Title { Text = "Machine Workloads", Position = "top", FontSize = 24, FontStyle = "bold", Display = true }, Legend = new Legend { Position = "bottom", Display = false } }; return(chart); }); return(generateChartTask); }
public static Dictionary <DataPointType, BarConfig> GetDataSets(AppState appState) { Dictionary <DataPointType, BarConfig> dataSets = new Dictionary <DataPointType, BarConfig>(); CreateConfigs(dataSets); SortedDictionary <int, Dictionary <string, Dictionary <DataPointType, double> > > DataPoints = new SortedDictionary <int, Dictionary <string, Dictionary <DataPointType, double> > >(); foreach (var item in appState.SimulationHistories) { double totalDeliveryTime = 0; double totalDeliveryDistance = 0; double totalDistance = 0; double totalTime = 0; double totalCost = 0; double avgDeliveryTime = 0; double avgDeliveryDistance = 0; double avgDeliveryCost = 0; foreach (var order in item.Steps.Last().ClosedOrders) { totalDeliveryTime += order.DeliveryTime ?? 0; totalDeliveryDistance += order.DeliveryDistance ?? 0; } foreach (var veh in item.Steps.Last().Vehicles) { totalDistance += veh.TotalTravelDistance; totalTime += veh.TotalTravelTime; } totalCost = item.Parameters.VehicleTemplate.PurchasingCost * item.Parameters.NumberOfVehicles + totalDistance * item.Parameters.VehicleTemplate.CostPerKm + totalTime * item.Parameters.VehicleTemplate.CostPerHour / 60 / 60; avgDeliveryTime = totalDeliveryTime / item.Parameters.NumberOfOrders; avgDeliveryCost = totalCost / item.Parameters.NumberOfOrders; if (!DataPoints.ContainsKey(item.Parameters.NumberOfVehicles)) { DataPoints.Add(item.Parameters.NumberOfVehicles, new Dictionary <string, Dictionary <DataPointType, double> >()); } if (!DataPoints[item.Parameters.NumberOfVehicles].ContainsKey(item.Parameters.VehicleTemplate.Name)) { DataPoints[item.Parameters.NumberOfVehicles][item.Parameters.VehicleTemplate.Name] = new Dictionary <DataPointType, double>(); } DataPoints[item.Parameters.NumberOfVehicles][item.Parameters.VehicleTemplate.Name][DataPointType.avgDeliveryTime] = avgDeliveryTime; DataPoints[item.Parameters.NumberOfVehicles][item.Parameters.VehicleTemplate.Name][DataPointType.avgDeliveryCost] = avgDeliveryCost; } var vehicle_types = new List <string>(); foreach (var veh_number in DataPoints) { foreach (var veh in veh_number.Value) { if (!vehicle_types.Contains(veh.Key)) { vehicle_types.Add(veh.Key); dataSets[DataPointType.avgDeliveryTime].Data.Labels.Add(veh.Key); dataSets[DataPointType.avgDeliveryCost].Data.Labels.Add(veh.Key); } } } Random r = new Random(); foreach (var item in DataPoints) { BarDataset <double> dataSetAvgDelTime = new BarDataset <double>() { BackgroundColor = ColorUtil.FromDrawingColor(Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255))), Label = $"{item.Key} vehicle(s)" }; BarDataset <double> dataSetAvgDeliveryCost = new BarDataset <double>() { BackgroundColor = ColorUtil.FromDrawingColor(Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255))), Label = $"{item.Key} vehicle(s)" }; foreach (var veh in vehicle_types) { if (item.Value.ContainsKey(veh)) { dataSetAvgDelTime.Add(item.Value[veh][DataPointType.avgDeliveryTime]); dataSetAvgDeliveryCost.Add(item.Value[veh][DataPointType.avgDeliveryCost]); } else { dataSetAvgDelTime.Add(0); dataSetAvgDeliveryCost.Add(0); } } dataSets[DataPointType.avgDeliveryTime].Data.Datasets.Add(dataSetAvgDelTime); dataSets[DataPointType.avgDeliveryCost].Data.Datasets.Add(dataSetAvgDeliveryCost); } return(dataSets); }
public Chart GenerateBarChart(List <double> resourceData) { Chart chart = new Chart { Type = "bar" }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data { Labels = new List <string>() { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" } }; BarDataset dataset = new BarDataset() { Label = "Electric energy consumption (kWh)", Data = resourceData, BackgroundColor = new List <string>() { "rgba(255, 99, 132, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(255, 206, 86, 0.2)", "rgba(75, 192, 192, 0.2)", "rgba(153, 102, 255, 0.2)", "rgba(255, 159, 64, 0.2)", "rgba(54, 159, 64, 0.2)" }, BorderColor = new List <string>() { "rgba(255,99,132,1)", "rgba(54, 162, 235, 1)", "rgba(255, 206, 86, 1)", "rgba(75, 192, 192, 1)", "rgba(153, 102, 255, 1)", "rgba(255, 159, 64, 1)", "rgba(54, 159, 64, 1)" }, BorderWidth = new List <int>() { 1 } }; data.Datasets = new List <Dataset> { dataset }; chart.Data = data; Options options = new Options() { Scales = new Scales(), Tooltips = new ToolTip() }; Scales scales = new Scales() { YAxes = new List <Object>() { new CartesianScale() { Ticks = new CartesianLinearTick() { BeginAtZero = true } } } }; ToolTip toolTip = new ToolTip { Enabled = true, Mode = "single", Callbacks = new Callback { Label = "function(tooltipItems, data) {return tooltipItems.yLabel + ' kWh';}" } }; options.Scales = scales; options.Tooltips = toolTip; chart.Options = options; return(chart); }
private Chart GenerateUserChart() { var chart = new Chart { Type = Enums.ChartType.Bar }; var data = new ChartJSCore.Models.Data { Labels = new List <string>() { "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December", "Januari", "Februari", "Maart", "April", "Mei" } }; var datasetSiteUsers = new BarDataset() { Label = "Nieuwe gebruikers zonder Discord", Data = new List <double?>(), BackgroundColor = new List <ChartColor> { ChartColor.FromRgba(0, 159, 227, 0.9), ChartColor.FromRgba(0, 159, 227, 0.9), ChartColor.FromRgba(0, 159, 227, 0.9), ChartColor.FromRgba(0, 159, 227, 0.9), ChartColor.FromRgba(0, 159, 227, 0.9), ChartColor.FromRgba(0, 159, 227, 0.9), ChartColor.FromRgba(0, 159, 227, 0.9), ChartColor.FromRgba(0, 159, 227, 0.9), ChartColor.FromRgba(0, 159, 227, 0.9), ChartColor.FromRgba(0, 159, 227, 0.9), ChartColor.FromRgba(0, 159, 227, 0.9), ChartColor.FromRgba(0, 159, 227, 0.9), }, BorderColor = new List <ChartColor> { ChartColor.FromRgb(0, 159, 227), ChartColor.FromRgb(0, 159, 227), ChartColor.FromRgb(0, 159, 227), ChartColor.FromRgb(0, 159, 227), ChartColor.FromRgb(0, 159, 227), ChartColor.FromRgb(0, 159, 227), ChartColor.FromRgb(0, 159, 227), ChartColor.FromRgb(0, 159, 227), ChartColor.FromRgb(0, 159, 227), ChartColor.FromRgb(0, 159, 227), ChartColor.FromRgb(0, 159, 227), ChartColor.FromRgb(0, 159, 227) }, }; var datasetDiscordUsers = new BarDataset() { Label = "Nieuwe gebruikers met Discord", Data = new List <double?>(), BackgroundColor = new List <ChartColor> { ChartColor.FromRgba(230, 0, 126, 0.9), ChartColor.FromRgba(230, 0, 126, 0.9), ChartColor.FromRgba(230, 0, 126, 0.9), ChartColor.FromRgba(230, 0, 126, 0.9), ChartColor.FromRgba(230, 0, 126, 0.9), ChartColor.FromRgba(230, 0, 126, 0.9), ChartColor.FromRgba(230, 0, 126, 0.9), ChartColor.FromRgba(230, 0, 126, 0.9), ChartColor.FromRgba(230, 0, 126, 0.9), ChartColor.FromRgba(230, 0, 126, 0.9), ChartColor.FromRgba(230, 0, 126, 0.9), ChartColor.FromRgba(230, 0, 126, 0.9) }, BorderColor = new List <ChartColor> { ChartColor.FromRgb(230, 0, 126), ChartColor.FromRgb(230, 0, 126), ChartColor.FromRgb(230, 0, 126), ChartColor.FromRgb(230, 0, 126), ChartColor.FromRgb(230, 0, 126), ChartColor.FromRgb(230, 0, 126), ChartColor.FromRgb(230, 0, 126), ChartColor.FromRgb(230, 0, 126), ChartColor.FromRgb(230, 0, 126), ChartColor.FromRgb(230, 0, 126), ChartColor.FromRgb(230, 0, 126), ChartColor.FromRgb(230, 0, 126) }, }; for (int i = 0; i < 12; i++) { var time = DateTime.Today.AddMonths(-i); var users = userRepository.GetAll() .Where(u => u.CreationDate.Month == time.Month) .ToList(); datasetSiteUsers.Data.Add(users.Count(u => u.DiscordUserName is null)); datasetDiscordUsers.Data.Add(users.Count(u => u.DiscordUserName is not null)); } data.Datasets = new List <Dataset> { datasetSiteUsers, datasetDiscordUsers }; chart.Data = data; return(chart); }
private async Task UpdateChart() { var totalDays = (int)(this.UserState.DateTimeEnd.Date - this.UserState.DateTimeBegin.Date).TotalDays; if (totalDays < 0) { return; } var axis = (BarTimeAxis)((BarConfig)_barChart.Config).Options.Scales.XAxes[0]; try { var granularity = totalDays <= 365 ? AvailabilityGranularity.Day : AvailabilityGranularity.Month; var availability = await this.UserState.GetAvailabilityAsync(granularity); var hasCleared = false; if (availability.Count != this.Config.Data.Datasets.Count) { this.Config.Data.Datasets.Clear(); hasCleared = true; } for (int i = 0; i < availability.Count; i++) { BarDataset <TimePoint> dataset; if (hasCleared) { var registration = availability[i].DataReaderRegistration; var isAggregation = registration.Equals(this.DatabaseManager.State.AggregationRegistration); dataset = new BarDataset <TimePoint> { Label = isAggregation ? "Aggregations" : $"Raw ({registration.RootPath} - {registration.DataReaderId})", BackgroundColor = _backgroundColors[i % _backgroundColors.Count()], BorderColor = _borderColors[i % _borderColors.Count()], BorderWidth = 2 }; this.Config.Data.Datasets.Add(dataset); } else { dataset = (BarDataset <TimePoint>) this.Config.Data.Datasets[i]; dataset.Clear(); } switch (granularity) { case AvailabilityGranularity.Day: axis.Time.Unit = TimeMeasurement.Day; dataset.AddRange(availability[i].Data .Select((entry, i) => { return(new TimePoint(entry.Key, entry.Value * 100)); }) ); break; case AvailabilityGranularity.Month: axis.Time.Unit = TimeMeasurement.Month; dataset.AddRange(availability[i].Data .Select((entry, i) => { return(new TimePoint(entry.Key, entry.Value * 100)); }) ); break; default: break; } } await _barChart.Update(); } catch (TaskCanceledException) { // prevent that the whole app crashes in the followig case: // - Nexus calculates aggregations and locks current file // GUI wants to load data from that locked file and times out // TaskCanceledException is thrown: app crashes. this.UserState.ClientState = ClientState.Normal; } catch (Exception ex) { this.UserState.Logger.LogError(ex.GetFullMessage()); this.ToasterService.ShowError(message: "Unable to load availability data.", icon: MatIconNames.Error_outline); } }
public static string GenerateBarChart() { Chart chart = new Chart(); chart.Type = "bar"; Data data = new Data(); data.Labels = new List <string>() { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" }; BarDataset dataset = new BarDataset() { Label = "# of Votes", Data = new List <double>() { 12, 19, 3, 5, 2, 3 }, BackgroundColor = new List <string>() { "rgba(255, 99, 132, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(255, 206, 86, 0.2)", "rgba(75, 192, 192, 0.2)", "rgba(153, 102, 255, 0.2)", "rgba(255, 159, 64, 0.2)" }, BorderColor = new List <string>() { "rgba(255,99,132,1)", "rgba(54, 162, 235, 1)", "rgba(255, 206, 86, 1)", "rgba(75, 192, 192, 1)", "rgba(153, 102, 255, 1)", "rgba(255, 159, 64, 1)" }, BorderWidth = new List <int>() { 1 } }; data.Datasets = new List <Dataset>(); data.Datasets.Add(dataset); chart.Data = data; BarOptions options = new BarOptions() { Scales = new Scales(), BarPercentage = 0.7 }; Scales scales = new Scales() { YAxes = new List <Scale>() { new CartesianScale() { Ticks = new CartesianLinearTick() { BeginAtZero = true } } } }; options.Scales = scales; chart.Options = options; chart.Options.Layout = new Layout() { Padding = new Padding() { PaddingObject = new PaddingObject() { Left = 10, Right = 12 } } }; string code = chart.CreateChartCode("barChart"); return(code); }
private Task <Chart> GenerateChartTask(List <string> paramsList) { var generateChartTask = Task.Run(() => { if (!_context.SimulationWorkschedules.Any()) { return(null); } Chart chart = new Chart { Type = "bar", Options = new Options { MaintainAspectRatio = true } }; var machines = new List <Kpi>(); // charttype foreach (var sim in _simList) { var trick17 = _context.Kpis.Where(x => x.SimulationConfigurationId == sim.Item1 && x.KpiType == KpiType.MachineUtilization && x.IsKpi && x.SimulationType == sim.Item2 && x.SimulationNumber == 1 && x.IsFinal).OrderByDescending(g => g.Name); machines.AddRange(trick17.ToList()); } var data = new Data { Labels = machines.Select(n => n.Name).Distinct().ToList() }; // create Dataset for each Lable data.Datasets = new List <Dataset>(); var i = 0; var cc = new ChartColor(); //var max = _context.SimulationWorkschedules.Max(x => x.End) - 1440; foreach (var t1 in _simList.OrderBy(x => x.Item1)) { var barDataSet = new BarDataset { Data = new List <double>(), BackgroundColor = new List <string>(), HoverBackgroundColor = new List <string>(), YAxisID = "y-normal" }; var barDiversityInvisSet = new BarDataset { Data = new List <double>(), BackgroundColor = new List <string>(), HoverBackgroundColor = new List <string>(), YAxisID = "y-diversity" }; var barDiversitySet = new BarDataset { Data = new List <double>(), BackgroundColor = new List <string>(), HoverBackgroundColor = new List <string>(), YAxisID = "y-diversity" }; barDataSet.Label = "Sim Id:" + t1.Item1 + " " + t1.Item2; foreach (var machineName in data.Labels) { Kpi machine = null; var t = machines.Where(x => x.Name == machineName && x.SimulationConfigurationId == t1.Item1 && x.SimulationType == t1.Item2).Distinct(); machine = t.Single(); var percent = Math.Round(machine.Value * 100, 2); // var wait = max - work; barDataSet.Data.Add(percent); barDataSet.BackgroundColor.Add(cc.Color[i].Substring(0, cc.Color[1].Length - 4) + "0.4)"); barDataSet.HoverBackgroundColor.Add(cc.Color[i].Substring(0, cc.Color[1].Length - 4) + "0.7)"); //var varianz = machine.Count * 100; //barDiversityInvisSet.Data.Add(percent - Math.Round(varianz / 2, 2)); //barDiversityInvisSet.BackgroundColor.Add(ChartColor.Transparent); //barDiversityInvisSet.HoverBackgroundColor.Add(ChartColor.Transparent); // //barDiversitySet.Data.Add(Math.Round(varianz, 2)); //barDiversitySet.BackgroundColor.Add(cc.Color[i].Substring(0, cc.Color[1].Length - 4) + (t + 0.3) + ")"); //barDiversitySet.HoverBackgroundColor.Add(cc.Color[i].Substring(0, cc.Color[1].Length - 4) + "1)"); } i++; i++; data.Datasets.Add(barDataSet); //data.Datasets.Add(barDiversityInvisSet); //data.Datasets.Add(barDiversitySet); } chart.Data = data; // Specifie xy Axis var xAxis = new List <Scale>() { new CartesianScale { Stacked = false, Id = "x-normal", Display = true } }; var yAxis = new List <Scale>() { new CartesianScale { Stacked = false, Display = true, Ticks = new CartesianLinearTick { BeginAtZero = true, Min = 0, Max = 100 }, Id = "y-normal" }, new CartesianScale { Stacked = false, Ticks = new CartesianLinearTick { BeginAtZero = true, Min = 0, Max = 100 }, Display = false, Id = "y-diversity", ScaleLabel = new ScaleLabel { LabelString = "Value in %", Display = false, FontSize = 12 }, }, }; //var yAxis = new List<Scale>() { new BarScale{ Ticks = new CategoryTick { Min = "0", Max = (yMaxScale * 1.1).ToString() } } }; chart.Options = new Options() { Scales = new Scales { XAxes = xAxis, YAxes = yAxis }, MaintainAspectRatio = false, Responsive = true, Legend = new Legend { Display = false } }; return(chart); }); return(generateChartTask); }
public async Task ChangeMode(string mode = "Years") { var data = await dataService.GetChartData(mode); await SetWidth(); //if (mode == "Years") //{ // data.Lables.AddRange(Enumerable.Repeat("test", 20)); // data.Data.AddRange(Enumerable.Repeat(20.2, 20)); //} minheight = data.Data.Count * 40 + 100; if (minheight < 400) { minheight = 400; } await InvokeAsync(() => StateHasChanged()); Reset = true; _chart = null; _config = null; await InvokeAsync(() => StateHasChanged()); await Task.Delay(25); SetConfig(); Reset = false; await InvokeAsync(() => StateHasChanged()); if (data == null) { _config.Options.Title.Text = "Keine Daten verfügbar."; _config.Options.Scales.XAxes.First().ScaleLabel.LabelString = "no data"; await _chart.Update(); return; } string Title = mode switch { "Years" => "Jahrgänge", "Classes" => "Klassen", _ => "Loading ..." }; _config.Options.Title.Text = Title; // _config.Options.Scales.YAxes.First().ScaleLabel.LabelString = "Title"; foreach (var label in data.Lables) { _config.Data.Labels.Add(label); } BarDataset <double> dataset = new BarDataset <double>(data.Data, horizontal: true) { BackgroundColor = Enumerable.Repeat("rgba(87, 66, 245, 0.8)", data.Data.Count).ToArray(), Label = "", BorderWidth = 1, BorderColor = "rgba(255, 0, 0, 1)", }; _config.Data.Datasets.Add(dataset); await _chart.Update(); firstActive = ""; } }
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 }); }