protected override async Task OnInitializedAsync() { // create data table to store data DataTable ChartData = new DataTable(); // Add columns to data table ChartData.Columns.Add("Programming Language", typeof(System.String)); ChartData.Columns.Add("Users", typeof(System.Double)); // Add rows to data table ChartData.Rows.Add("Java", 62000); ChartData.Rows.Add("Python", 46000); ChartData.Rows.Add("Javascript", 38000); ChartData.Rows.Add("C++", 31000); ChartData.Rows.Add("C#", 27000); ChartData.Rows.Add("PHP", 14000); ChartData.Rows.Add("Perl", 14000); // Create static source with this data table StaticSource source = new StaticSource(ChartData); // Create instance of DataModel class DataModel model = new DataModel(); // Add DataSource to the DataModel model.DataSources.Add(source); // Instantiate Column Chart Charts.ColumnChart column = new Charts.ColumnChart("first_chart"); // Set Chart's width and height column.Width.Pixel(700); column.Height.Pixel(400); // Set DataModel instance as the data source of the chart column.Data.Source = model; // Set Chart Title column.Caption.Text = "Most popular programming language"; // Set chart sub title column.SubCaption.Text = "2017-2018"; // hide chart Legend column.Legend.Show = false; // set XAxis Text column.XAxis.Text = "Programming Language"; // Set YAxis title column.YAxis.Text = "User"; // set chart theme column.ThemeName = FusionChartsTheme.ThemeName.FUSION; // set chart rendering json ChartJson = column.Render(); }
public async Task OnPostAsync() { const string path = @"..\车辆基本信息表.csv"; CarDetails = new List <CarDetail>(); var lists = FileService.ReadFromFile(path); CarDetails = InitializeService.InitializeCarDetail(lists); sta = new List <CarStatic>(); Dictionary <string, CarStatic> dic = new Dictionary <string, CarStatic>(); foreach (var item in CarDetails) { if (dic.ContainsKey(item.CarType)) { ++dic[item.CarType].Total; if (item.State == "y") { ++dic[item.CarType].rent; } else { ++dic[item.CarType].free; } } else { int onrent = item.State == "y" ? 1 : 0; dic.Add(item.CarType, new CarStatic { Type = item.CarType, Total = 1, rent = onrent, free = 1 - onrent }); } } foreach (var item in dic) { sta.Add(item.Value); } switch (SearchOption) { case "TotalInfo": break; case "BarChart": try { DataTable ChartData = new DataTable(); ChartData.Columns.Add("Programming Language", typeof(System.String)); ChartData.Columns.Add("Users", typeof(int)); foreach (var item in sta) { ChartData.Rows.Add(item.Type, item.Total); } // Create static source with this data table StaticSource source = new StaticSource(ChartData); // Create instance of DataModel class DataModel model = new DataModel(); // Add DataSource to the DataModel model.DataSources.Add(source); // Instantiate Column Chart Charts.ColumnChart column = new Charts.ColumnChart("first_chart"); // Set Chart's width and height column.Width.Pixel(700); column.Height.Pixel(400); // Set DataModel instance as the data source of the chart column.Data.Source = model; // Set Chart Title column.Caption.Text = "All type of the cars"; // Set chart sub title column.SubCaption.Text = "2020.06"; // hide chart Legend column.Legend.Show = false; // set XAxis Text column.XAxis.Text = "CarType"; // Set YAxis title column.YAxis.Text = "Total"; // set chart theme column.ThemeName = FusionChartsTheme.ThemeName.FUSION; // set chart rendering json ChartJson = column.Render(); }catch { } break; default: break; } }
public async Task <IActionResult> OnGetAsync(string id) { if (id == null) { return(NotFound()); } controller = await _context.Controllers.FirstOrDefaultAsync(m => m.Id == id); string[] values = controller.Values; if (values.Length == 0) { return(Page()); } int start_point = 0; // create data table to store data DataTable ChartData = new DataTable(); // Add columns to data table if (controller.Type == "humidity") { ChartData.Columns.Add("time", typeof(System.String)); ChartData.Columns.Add("mm/pt", typeof(System.Double)); foreach (var item in values) { if (item != "") { ChartData.Rows.Add(start_point, item.Split('|')[1]); start_point += 10; } } } else if (controller.Type == "temperature") { ChartData.Columns.Add("time", typeof(System.String)); ChartData.Columns.Add("Degrees", typeof(System.Double)); foreach (var item in values) { double dd = 0; if (item != "") { ChartData.Rows.Add(start_point, item.Split('|')[1]); start_point += 10; } } } else if (controller.Type == "pressure") { ChartData.Columns.Add("time", typeof(System.String)); ChartData.Columns.Add("bar", typeof(System.Double)); foreach (var item in values) { //DateTime dt = DateTime.Parse(item.Split('|')[0]); ChartData.Rows.Add(start_point, item.Split('|')[3]); start_point += 10; } start_point = 0; } else if (controller.Type == "movement") { ChartData.Columns.Add("time", typeof(System.String)); ChartData.Columns.Add("actions", typeof(System.Double)); foreach (var item in values) { if (item != "") { //DateTime dt = DateTime.Parse(item.Split('|')[0]); int value = 0; if (item.Split('|')[1] == "true") { value = 1; } ChartData.Rows.Add(start_point, value); start_point += 10; } } } else if (controller.Type == "lightning") { ChartData.Columns.Add("time", typeof(System.String)); ChartData.Columns.Add("lux", typeof(System.Double)); foreach (var item in values) { if (item != "") { //DateTime dt = DateTime.Parse(item.Split('|')[0]); ChartData.Rows.Add(start_point, item.Split('|')[1]); start_point += 10; } } } else { ChartData.Columns.Add("sample", typeof(System.String)); ChartData.Columns.Add("sample2", typeof(System.Double)); } // Add rows to data table //ChartData.Rows.Add("Java", 62000); //ChartData.Rows.Add("Python", 46000); //ChartData.Rows.Add("Javascript", 38000); //ChartData.Rows.Add("C++", 31000); //ChartData.Rows.Add("C#", 27000); //ChartData.Rows.Add("PHP", 14000); //ChartData.Rows.Add("Perl", 14000); // Create static source with this data table StaticSource source = new StaticSource(ChartData); // Create instance of DataModel class DataModel model = new DataModel(); // Add DataSource to the DataModel model.DataSources.Add(source); // Instantiate Column Chart Charts.ColumnChart column = new Charts.ColumnChart("first_chart"); // Set Chart's width and height column.Width.Pixel(700); column.Height.Pixel(400); // Set DataModel instance as the data source of the chart column.Data.Source = model; // Set Chart Title column.Caption.Text = controller.Type; // Set chart sub title // hide chart Legend column.Legend.Show = false; // set XAxis Text column.XAxis.Text = "Time"; // Set YAxis title column.YAxis.Text = "Value"; // set chart theme column.ThemeName = FusionChartsTheme.ThemeName.FUSION; // set chart rendering json ChartJson = column.Render(); if (controller == null) { return(NotFound()); } return(Page()); }
public IActionResult Diagram() { DataTable ChartData = new DataTable(); ChartData.Columns.Add("Стоимость", typeof(double)); ChartData.Columns.Add("Спрос", typeof(int)); var sales = _saleLogic.Read(null); var products = _productLogic.Read(null); var spros = new List <int>(); var prices = new List <double>(); if (products != null) { foreach (var product in products) { prices.Add(product.Price); spros.Add(0); } } if (sales != null) { foreach (var sale in sales) { if (sale.TableProducts != null) { foreach (var tp in sale.TableProducts) { foreach (var product in products) { if (tp.Product == product) { spros[products.IndexOf(product)] += tp.Amount; } } } } } } for (int i = 0; i < products.Count(); i++) { ChartData.Rows.Add(prices[i], spros[i]); } StaticSource source = new StaticSource(ChartData); DataModel model = new DataModel(); model.DataSources.Add(source); Charts.ColumnChart column = new Charts.ColumnChart("first_chart"); column.Width.Pixel(700); column.Height.Pixel(400); column.Data.Source = model; column.Caption.Text = "Диаграмма цена/спрос"; column.Legend.Show = false; column.XAxis.Text = "Стоимость"; column.YAxis.Text = "Спрос"; column.ThemeName = FusionChartsTheme.ThemeName.FUSION; return(View("Diagram", column.Render())); }