private Chart GetSpendingByDateChart(StatisticsViewModel statisticsViewModel) { Chart chart = new Chart(); Data data = new Data(); data.Datasets = new List <Dataset>(); chart.Data = data; chart.Type = Enums.ChartType.Line; var dates = statisticsViewModel.SpendingByDateMap.Keys.ToList(); var values = statisticsViewModel.SpendingByDateMap.Values.ToList(); data.Labels = dates; LineDataset dataset = new LineDataset() { Label = "Spending", Data = values, Fill = "false", LineTension = 0.1, BackgroundColor = ChartColor.FromRgba(75, 192, 192, 0.4), BorderColor = ChartColor.FromRgb(75, 192, 192), BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointHoverBorderColor = new List <ChartColor> { ChartColor.FromRgb(220, 220, 220) }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; data.Datasets.Add(dataset); return(chart); }
public void FromRgb_Populates_Alpha_With_One() { double expectedAlpha = 1.0; var actualColor = ChartColor.FromRgb(0, 0, 0); Assert.AreEqual(expectedAlpha, actualColor.Alpha); }
public void FromRgb_Populates_Correct_Values() { byte expectedRed = 66; byte expectedGreen = 99; byte expectedBlue = 111; var actualColor = ChartColor.FromRgb(expectedRed, expectedGreen, expectedBlue); Assert.AreEqual(expectedRed, actualColor.Red); Assert.AreEqual(expectedGreen, actualColor.Green); Assert.AreEqual(expectedBlue, actualColor.Blue); }
private static Chart GenerateBubbleChart() { var chart = new Chart { Type = Enums.ChartType.Bubble }; var data = new Data(); var dataset = new BubbleDataset { Label = "Bubble Dataset", Data = new List <BubbleData>() }; var bubbleData1 = new BubbleData(); var bubbleData2 = new BubbleData(); bubbleData1.X = 20; bubbleData1.Y = 30; bubbleData1.R = 15; dataset.Data.Add(bubbleData1); bubbleData2.X = 40; bubbleData2.Y = 10; bubbleData2.R = 10; dataset.Data.Add(bubbleData2); data.Datasets = new List <Dataset> { dataset }; dataset.BackgroundColor = new List <ChartColor> { ChartColor.FromRgb(255, 99, 132) }; dataset.HoverBackgroundColor = new List <ChartColor> { ChartColor.FromRgb(255, 99, 132) }; chart.Data = data; return(chart); }
public Chart GeneratePointsOfStudentsBarChart() { Chart chart = new Chart(); chart.Type = Enums.ChartType.Bar; Data data = new Data(); List <StudentExam> studentExams = _studentExamManager.GetAll().ToList(); List <string> studentNames = new List <string>(); foreach (var item in studentExams) { studentNames.Add(item.Student.FullName); } data.Labels = studentNames; List <double> scores = new List <double>(); foreach (var item in studentExams) { scores.Add(item.Points); } BarDataset dataset = new BarDataset() { Label = "Score", Data = scores, 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>(); data.Datasets.Add(dataset); chart.Data = data; var options = new Options { Scales = new Scales() }; var scales = new Scales { YAxes = new List <Scale> { new CartesianScale { Ticks = new CartesianLinearTick { BeginAtZero = true } } }, XAxes = new List <Scale> { new BarScale { BarPercentage = 0.5, BarThickness = 6, MaxBarThickness = 8, MinBarLength = 2, GridLines = new GridLine() { OffsetGridLines = 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 static ChartColor GetGreyBorder() { return(ChartColor.FromRgb(201, 203, 207)); }
public static ChartColor GetPurpleBorder() { return(ChartColor.FromRgb(153, 102, 255)); }
//Estadisticas y clasificacion de nivel de gastos public async Task <IActionResult> ExpensesAndIncomes() { //Chart instance Chart chart = new Chart(); Chart chartIncomes = new Chart(); Chart chartBalance = new Chart(); //Getting the user and setting the userId var user = await _userManager.GetUserAsync(HttpContext.User); var userId = user.Id; //User expenses List <Expense> listagastos = _db.Expenses.Where(x => x.UserId == userId).ToList(); //User profile List <Profile> listasalario = _db.Profiles.Where(x => x.UserId == userId).ToList(); //User incomes List <Income> listaentradas = _db.Incomes.Include(x => x.IncomeSource).Where(x => x.IncomeSource.UserId == userId).ToList(); //Setting the chart type chart.Type = Enums.ChartType.Line; chartIncomes.Type = Enums.ChartType.Line; chartBalance.Type = Enums.ChartType.Line; //Extracting the expenses data List <double> total = listagastos.Select(x => Convert.ToDouble(x.Total)).ToList(); List <double> totalsalario = listasalario.Select(x => Convert.ToDouble(x.Salary)).ToList(); double salariototal = totalsalario[0]; ViewBag.salariototal = salariototal; //Extracting the incomes data List <double> totalIncomes = listagastos.Select(x => Convert.ToDouble(x.Total)).ToList(); List <double> totalmes = new List <double>() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; List <double> totalEntradasMes = new List <double>() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; List <double> totalBalance = new List <double>() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; foreach (Expense item in listagastos) { for (int i = 0; i <= 11; i++) { if (item.CreationDate.Month - 1 == i) { var elemento = totalmes.ElementAt(i); elemento += Convert.ToDouble(item.Total); totalmes.RemoveAt(i); totalmes.Insert(i, elemento); } } } foreach (Income item in listaentradas) { for (int i = 0; i <= 11; i++) { if (item.CreationDate.Month - 1 == i) { var elemento = totalEntradasMes.ElementAt(i); elemento += Convert.ToDouble(item.Total); totalEntradasMes.RemoveAt(i); totalEntradasMes.Insert(i, elemento); } } } for (int i = 0; i <= 11; i++) { double monthBalance = salariototal - totalmes.ElementAt(i) - totalEntradasMes.ElementAt(i); totalBalance.RemoveAt(i); totalBalance.Insert(i, monthBalance); } int indicemes = DateTime.Now.Month; double gastototal = totalmes[indicemes - 1]; double a = salariototal - gastototal; double porcentaje = (a * 100) / salariototal; ViewBag.porcentaje = porcentaje; //Data object for expenses ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); //Data object for incomes ChartJSCore.Models.Data dataIncomes = new ChartJSCore.Models.Data(); //Data object for balance ChartJSCore.Models.Data dataBalance = new ChartJSCore.Models.Data(); List <string> months = new List <string>() { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }; data.Labels = months; dataIncomes.Labels = months; dataBalance.Labels = months; //Dataset for expenses chart LineDataset dataset = new LineDataset() { Label = "Gastos por mes", Data = totalmes, Fill = "false", LineTension = 0.1, BackgroundColor = ChartColor.FromRgba(75, 192, 192, 0.4), BorderColor = ChartColor.FromRgb(75, 192, 192), BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointHoverBorderColor = new List <ChartColor> { ChartColor.FromRgb(220, 220, 220) }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; //Dataset for incomes chart LineDataset datasetIncomes = new LineDataset() { Label = "Entradas por mes", Data = totalEntradasMes, Fill = "false", LineTension = 0.1, BackgroundColor = ChartColor.FromRgba(75, 192, 192, 0.4), BorderColor = ChartColor.FromRgb(75, 192, 192), BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointHoverBorderColor = new List <ChartColor> { ChartColor.FromRgb(220, 220, 220) }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; //Dataset for balance chart LineDataset datasetBalance = new LineDataset() { Label = "Balance por mes", Data = totalBalance, Fill = "false", LineTension = 0.1, BackgroundColor = ChartColor.FromRgba(75, 192, 192, 0.4), BorderColor = ChartColor.FromRgb(75, 192, 192), BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointHoverBorderColor = new List <ChartColor> { ChartColor.FromRgb(220, 220, 220) }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; data.Datasets = new List <Dataset>(); data.Datasets.Add(dataset); chart.Data = data; dataIncomes.Datasets = new List <Dataset>(); dataIncomes.Datasets.Add(datasetIncomes); chartIncomes.Data = dataIncomes; dataBalance.Datasets = new List <Dataset>(); dataBalance.Datasets.Add(datasetBalance); chartBalance.Data = dataBalance; //Sending data to the view ViewData["expenses"] = chart; ViewData["incomes"] = chartIncomes; ViewData["balance"] = chartBalance; return(View()); }
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); }
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); }
public static ChartColor GetRedBorder() { return(ChartColor.FromRgb(255, 99, 132)); }
public IActionResult OnGet() { if (HttpContext.Session.GetString("email") == null) { return(RedirectToPage("Login")); } Costs = CostsRepository.GetCostsByEmail(HttpContext.Session.GetString("email")); Vehicles = VehiclesRepository.GetVehiclesByEmail(HttpContext.Session.GetString("email")); //Calculates all overdue fixedCosts foreach (var item in Vehicles) { CostsRepository.FixedCostsMontly(item.License); } //Chart settings Chart chart = new Chart(); chart.Type = Enums.ChartType.Line; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); data.Labels = new List <string>() { "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December" }; data.Datasets = new List <Dataset>(); Random random = new Random(); var year = HttpContext.Request.Query["Year"]; if (!string.IsNullOrWhiteSpace(year)) { Year = Convert.ToInt32(year); } else { Year = DateTime.Now.Year; } //Foreach to loop through every vehicle to get AnnualCosts and set it in the chart foreach (var vehicle in Vehicles) { int[,] randomColor = new int[3, 1] { { random.Next(0, 255) }, { random.Next(0, 255) }, { random.Next(0, 255) } }; IList <double?> annualCosts = CostsRepository.GetAnnualCosts(vehicle.License, Year); LineDataset dataset = new LineDataset() { Label = vehicle.Brand_Name + ' ' + vehicle.Model_Name, Data = annualCosts, Fill = "false", LineTension = 0.1, BackgroundColor = ChartColor.FromRgba((byte)randomColor[0, 0], (byte)randomColor[1, 0], (byte)randomColor[2, 0], 0.4), BorderColor = ChartColor.FromRgb((byte)randomColor[0, 0], (byte)randomColor[1, 0], (byte)randomColor[2, 0]), BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointHoverBorderColor = new List <ChartColor> { ChartColor.FromRgb(220, 220, 220) }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; data.Datasets.Add(dataset); } chart.Data = data; ViewData["chart"] = chart; return(Page()); }
private static Chart GenerateBarChart() { Chart chart = new Chart(); chart.Type = Enums.ChartType.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 <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>(); data.Datasets.Add(dataset); chart.Data = data; var options = new Options { Scales = new Scales() }; var scales = new Scales { YAxes = new List <Scale> { new CartesianScale { Ticks = new CartesianLinearTick { BeginAtZero = true } } }, XAxes = new List <Scale> { new BarScale { BarPercentage = 0.5, BarThickness = 6, MaxBarThickness = 8, MinBarLength = 2, GridLines = new GridLine() { OffsetGridLines = 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 Chart GenerateNumberOfCoursesBarChart() { Chart chart = new Chart(); chart.Type = Enums.ChartType.Bar; Data data = new Data(); List <Course> courses = _courseManager.GetAll().ToList(); List <string> course = new List <string>() { "Courses" }; data.Labels = course; List <double> numberOfCourses = new List <double>(); numberOfCourses.Add(courses.Count()); BarDataset dataset = new BarDataset() { Label = "# of Courses", Data = numberOfCourses, 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>(); data.Datasets.Add(dataset); chart.Data = data; var options = new Options { Scales = new Scales() }; var scales = new Scales { YAxes = new List <Scale> { new CartesianScale { Ticks = new CartesianLinearTick { BeginAtZero = true } } }, XAxes = new List <Scale> { new BarScale { BarPercentage = 0.5, BarThickness = 6, MaxBarThickness = 8, MinBarLength = 2, GridLines = new GridLine() { OffsetGridLines = 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 static ChartColor GetOrangeBorder() { return(ChartColor.FromRgb(255, 159, 64)); }
private static Chart GenerateBarChartForYearOnYear(List <Project> listOfProjects) { Chart chart = new Chart(); chart.Type = Enums.ChartType.Bar; Data data = new Data(); List <List <Project> > result = listOfProjects .GroupBy(p => p.ArticleDate.Year) .Select(g => g.ToList()) .ToList(); List <string> datalabels = new List <string>(); Dictionary <string, List <Project> > yearMap = new Dictionary <string, List <Project> >(); Dictionary <string, double> counterMap = new Dictionary <string, double>(); foreach (var projectListByYear in result) { datalabels.Add(projectListByYear[0].ArticleDate.Year.ToString()); yearMap.Add(projectListByYear[0].ArticleDate.Year.ToString(), projectListByYear); counterMap.Add(projectListByYear[0].ArticleDate.Year.ToString(), (double)projectListByYear.Count); } List <double> countList = new List <double>(); data.Labels = datalabels; foreach (var year in data.Labels) { if (counterMap.TryGetValue(year, out double indResult)) { countList.Add(indResult); } } //Maybe this foreach and the one above could be merged? List <ChartColor> listOfBackgroundColors = new List <ChartColor>(); List <ChartColor> listOfBorderColors = new List <ChartColor>(); Random r = new Random(); foreach (var year in data.Labels) { listOfBackgroundColors.Add(ChartColor.FromRgba((byte)r.Next(1, 255), (byte)r.Next(1, 255), (byte)r.Next(1, 255), 0.2)); listOfBorderColors.Add(ChartColor.FromRgb(listOfBackgroundColors.Last().Red, listOfBackgroundColors.Last().Green, listOfBackgroundColors.Last().Blue)); } BarDataset dataset = new BarDataset() { Label = "# of projects per year", Data = countList, BackgroundColor = listOfBackgroundColors, BorderColor = listOfBorderColors, BorderWidth = new List <int>() { 1 } }; data.Datasets = new List <Dataset>(); data.Datasets.Add(dataset); chart.Data = data; var options = new Options { Scales = new Scales() }; var scales = new Scales { YAxes = new List <Scale> { new CartesianScale { Ticks = new CartesianLinearTick { BeginAtZero = true } } }, XAxes = new List <Scale> { new BarScale { BarPercentage = 0.5, BarThickness = 6, MaxBarThickness = 8, MinBarLength = 2, GridLines = new GridLine() { OffsetGridLines = 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 static ChartColor GetYellowBorder() { return(ChartColor.FromRgb(255, 205, 86)); }
/// <summary> /// Retourne le graphique intégré à l'espace administrauter: nombre de nouvelles notes par mois /// </summary> /// <param name="nbMonths">Nombre de mois avant celui en cours</param> /// <param name="Notes">Liste de notes</param> public static Chart GenerateChartNotes(int nbMonths, List <Note> Notes) { List <string> monthLabels = new List <string>(); List <double?> noteCounter = new List <double?>(); DateTime dateVar = DateTime.Now; for (int i = 0; i < nbMonths; i++) // Création d'une liste de mois, contenant les n mois inférieurs à celui en cours { monthLabels.Add(dateVar.ToString("MM/yyyy")); dateVar = dateVar.AddMonths(-1); } monthLabels.Reverse(); foreach (string monthY in monthLabels) // Création du set de données du graphique { int nbNotes = 0; foreach (Note note in Notes) { if (note.DateCreation.Month.ToString("00") + "/" + note.DateCreation.Year.ToString("0000") == monthY) { nbNotes++; } } noteCounter.Add(nbNotes); } Chart chart = new Chart { Type = Enums.ChartType.Line }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data { Labels = monthLabels }; LineDataset dataset = new LineDataset() // Paramètrage du graphique { Label = "Créations", Data = noteCounter, Fill = "false", LineTension = 0.1, BackgroundColor = ChartColor.FromRgba(75, 192, 192, 0.4), BorderColor = ChartColor.FromRgb(75, 192, 192), BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointHoverBorderColor = new List <ChartColor> { ChartColor.FromRgb(220, 220, 220) }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; data.Datasets = new List <Dataset> { dataset }; chart.Data = data; return(chart); }
public static ChartColor GetGreenBorder() { return(ChartColor.FromRgb(75, 192, 192)); }
private Chart GetGoalChart(StatisticsViewModel statisticsViewModel) { Chart chart = new Chart(); Data data = new Data(); data.Datasets = new List <Dataset>(); chart.Data = data; chart.Type = Enums.ChartType.Line; data.Labels = new List <string>() { "asd", "asd", "asd", "asd", "asd", "asd", "asd" }; LineDataset dataset = new LineDataset() { Label = "TestChart", Data = new List <double?> { 65, 59, 80, 81, 56, 55, 40 }, Fill = "false", LineTension = 0.1, BackgroundColor = ChartColor.FromRgba(75, 192, 192, 0.4), BorderColor = ChartColor.FromRgb(75, 192, 192), BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointHoverBorderColor = new List <ChartColor> { ChartColor.FromRgb(220, 220, 220) }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; data.Datasets.Add(dataset); return(chart); }
public static ChartColor GetBlueBorder() { return(ChartColor.FromRgb(54, 162, 235)); }
private static Chart GenerateLineChart() { var chart = new Chart { Type = Enums.ChartType.Line }; var data = new Data { Labels = new List <string> { "January", "February", "March", "April", "May", "June", "July" } }; var dataset = new LineDataset { Label = "My First dataset", Data = new List <double> { 65, 59, 80, 81, 56, 55, 40 }, Fill = "false", LineTension = 0.1, BackgroundColor = ChartColor.FromRgba(75, 192, 192, 0.4), BorderColor = ChartColor.FromRgb(75, 192, 192), BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <ChartColor> { ChartColor.FromRgb(75, 192, 192) }, PointHoverBorderColor = new List <ChartColor> { ChartColor.FromRgb(220, 220, 220) }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; data.Datasets = new List <Dataset> { dataset }; var options = new Options { Scales = new Scales() }; var scales = new Scales { YAxes = new List <Scale> { new CartesianScale() } }; var yAxes = new CartesianScale { Ticks = new Tick() }; var tick = new Tick { Callback = "function(value, index, values) {return '$' + value;}" }; yAxes.Ticks = tick; scales.YAxes = new List <Scale> { yAxes }; options.Scales = scales; chart.Options = options; chart.Data = data; return(chart); }
private static Chart GenerateRadarChart() { var chart = new Chart { Type = Enums.ChartType.Radar }; var data = new Data { Labels = new List <string> { "Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running" } }; var dataset1 = new RadarDataset { Label = "My First dataset", BackgroundColor = ChartColor.FromRgba(179, 181, 198, 0.2), BorderColor = ChartColor.FromRgb(179, 181, 198), PointBackgroundColor = new List <ChartColor> { ChartColor.FromRgb(179, 181, 198) }, PointBorderColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointHoverBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointHoverBorderColor = new List <ChartColor> { ChartColor.FromRgb(179, 181, 198) }, Data = new List <double?> { 65, 59, null, 81, 56, 55, 40 } }; var dataset2 = new RadarDataset { Label = "My Second dataset", BackgroundColor = ChartColor.FromRgba(255, 99, 132, 0.2), BorderColor = ChartColor.FromRgb(255, 99, 132), PointBackgroundColor = new List <ChartColor> { ChartColor.FromRgb(255, 99, 132) }, PointBorderColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointHoverBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointHoverBorderColor = new List <ChartColor> { ChartColor.FromRgb(255, 99, 132) }, Data = new List <double?> { 28, 48, 40, null, 96, 27, 100 } }; data.Datasets = new List <Dataset> { dataset1, dataset2 }; chart.Data = data; return(chart); }