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); }
public static Task <bool> InitializeMixedChart(MixedChartConfig mixedChart) { return(JSRuntime.Current.InvokeAsync <bool>("ChartJSInterop.InitializeChart", mixedChart)); }
public static Task <bool> UpdateMixedChart(MixedChartConfig mixedChartConfig) { return(JSRuntime.Current.InvokeAsync <bool>("ChartJSInterop.UpdateChart", mixedChartConfig)); }
public static Task <bool> ReloadMixedChart(MixedChartConfig mixedChart) { return(JSRuntime.Current.InvokeAsync <bool>("ChartJSInterop.ReloadChart", mixedChart)); }