コード例 #1
0
        public async static Task <BarChartConfig> GetBarChartConfig()
        {
            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 }).ToList();


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

            foreach (var value in values)
            {
                dynValues.Add(value);
            }



            var barChartConfig = new BarChartConfig()
            {
                CanvasId = "forcastBarChartCanvas",
                Options  = new BarChartOptions
                {
                    Text       = "24 Hour Forecast",
                    Display    = true,
                    Responsive = true
                },
                Data = new BarChartData
                {
                    Labels   = orderedData.Select(x => x.Date).ToList(),
                    Datasets = new List <BaseBarChartDataset>
                    {
                        new BarChartDataset
                        {
                            Label           = "Temperature",
                            BackgroundColor = ColorUtil.ColorString(0, 50, 255),
                            BorderColor     = ColorUtil.ColorString(0, 255, 128),
                            Data            = dynValues
                        }
                    }
                }
            };

            return(barChartConfig);
        }
コード例 #2
0
        protected override void OnInit()
        {
            barChartConfig = barChartConfig ?? new BarChartConfig
            {
                CanvasId = "myBarChartCanvas",

                Options = new BarChartOptions
                {
                    Text       = "Sample chart from Blazor",
                    Display    = true,
                    Responsive = true,
                    Legend     = new Legend
                    {
                        Position = LegendPosition.BOTTOM.ToString(),
                        Labels   = new Labels
                        {
                            UsePointStyle = true
                        }
                    },
                    Scales = new BarChartOptionsScales
                    {
                        xAxes = new List <BarChartAxis>
                        {
                            new BarChartAxis
                            {
                                Stacked = true
                            }
                        }.ToArray(),
                        yAxes = new List <BarChartAxis>
                        {
                            new BarChartAxis
                            {
                                Stacked = true
                            }
                        }.ToArray()
                    }
                },
            };
        }
コード例 #3
0
 public static Task <bool> UpdateBarChart(BarChartConfig barChartConfig)
 {
     return(JSRuntime.Current.InvokeAsync <bool>("ChartJSInterop.UpdateChart", barChartConfig));
 }