private void SetSessionGraph() { var request = _service.Data.Ga.Get( "ga:" + WebsiteCode, DateTime.Today.AddDays(-7).ToString("yyyy-MM-dd"), DateTime.Today.ToString("yyyy-MM-dd"), "ga:sessions"); request.Dimensions = "ga:year,ga:month,ga:day"; var data = request.Execute(); var days = EachDay(DateTime.UtcNow.AddDays(-7), DateTime.UtcNow) .Select(day => day.ToString("dd MMMM")) .ToList(); var values = data.Rows .Select(row => double.Parse(row[3])) .ToList(); var datas = new ChartJSCore.Models.Data { Labels = days, Datasets = new List <Dataset> { CreateDataset(values, "Totaal aantal sessie's") } }; var chart = new Chart { Type = "line", Data = datas }; ViewBag.sessions = chart; }
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); }
private Chart GeneratePieChart(List <Track> tracks) { Chart chart = new Chart { Type = Enums.ChartType.Pie, }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data { Labels = Enum.GetNames(typeof(JudgeStatus)) }; PieDataset dataset = new PieDataset { Label = "Summary", BackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#28A745"), ChartColor.FromHexString("#FFC720"), ChartColor.FromHexString("#DC3545"), ChartColor.FromHexString("#1B6EC2"), ChartColor.FromHexString("#6C757D") }, HoverBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#28A745"), ChartColor.FromHexString("#FFC720"), ChartColor.FromHexString("#DC3545"), ChartColor.FromHexString("#1B6EC2"), ChartColor.FromHexString("#6C757D") }, Data = new List <double?> { tracks.LongCount(x => x.Status == JudgeStatus.Accept), tracks.LongCount(x => x.Status == JudgeStatus.WrongAnswer), tracks.LongCount(x => x.Status == JudgeStatus.CompileError), tracks.LongCount(x => x.Status == JudgeStatus.UnknownError), tracks.LongCount(x => x.Status == JudgeStatus.Pending) }, }; data.Datasets = new List <Dataset> { dataset }; chart.Data = data; return(chart); }
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 Chart GenerateAmountVerenigingenBoughtTicketsChart(McEditie editie) { Chart chart = new Chart() { Type = Enums.ChartType.Doughnut, Options = new Options() { Title = new Title() { Display = true, Position = "top", Text = "Aantal verenigingen met tickets", FontSize = 20 } } }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data { Labels = new List <string>() { "Verenigingen met tickets", "Verenigingen zonder tickets" }, Datasets = new List <Dataset>() }; int verenigingenWithTicketsCount = _verenigingRepository.GetAllWhoHaveTickets(editie.Id).Count(); int verenigingenCount = _verenigingRepository.GetAll().Count(); PieDataset dataset = new PieDataset() { BackgroundColor = new List <ChartColor>() { ChartColorSolid[2], ChartColorSolid[3] }, HoverBackgroundColor = new List <ChartColor>() { ChartColorSolid[2], ChartColorSolid[3] }, Data = new List <double>() { verenigingenWithTicketsCount, verenigingenCount - verenigingenWithTicketsCount } }; data.Datasets.Add(dataset); chart.Data = data; return(chart); }
private Chart GenerateAmountTicketSoldChart(McEditie editie) { Chart chart = new Chart() { Type = Enums.ChartType.Doughnut, Options = new Options() { Title = new Title() { Display = true, Position = "top", Text = "Aantal verkochte tickets", FontSize = 20 } } }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data { Labels = new List <string>() { "Aantal verkochte tickets", "Aantal beschikbare tickets" }, Datasets = new List <Dataset>() }; int ticketsRemaining = editie.GetAmountTicketsRemaining(); PieDataset dataset = new PieDataset() { BackgroundColor = new List <ChartColor>() { ChartColorSolid[2], ChartColorSolid[3] }, HoverBackgroundColor = new List <ChartColor>() { ChartColorSolid[2], ChartColorSolid[3] }, Data = new List <double>() { editie.MaxTickets - ticketsRemaining, ticketsRemaining } }; data.Datasets.Add(dataset); chart.Data = data; return(chart); }
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); }
public async Task <string> SetDownloadsGraph(int?id) { var downloads = await _downloadLogRepository.GetDownloadsLastWeek(id); var lastWeek = DateTime.UtcNow.AddDays(-7); var values = new List <double>(); for (var i = 0; i <= 7; i++) { var found = false; foreach (var date in downloads.Keys) { if (date.ToString("dd MMMM") != lastWeek.ToString("dd MMMM")) { continue; } values.Add(downloads[date]); found = true; break; } if (!found) { values.Add(0); } lastWeek = lastWeek.AddDays(1); } var labels = EachDay(DateTime.UtcNow.AddDays(-7), DateTime.UtcNow) .Select(day => day.ToString("dd MMMM")) .ToList(); var datas = new ChartJSCore.Models.Data { Labels = labels, Datasets = new List <Dataset> { CreateDataset(values, "Totaal aantal downloads") } }; var chart = new Chart { Type = "line", Data = datas }; return(chart.CreateChartCode("downloadGraph")); }
private void SetDeviceGraph() { var request = _service.Data.Ga.Get( "ga:" + WebsiteCode, DateTime.Today.AddDays(-7).ToString("yyyy-MM-dd"), DateTime.Today.ToString("yyyy-MM-dd"), "ga:sessions"); request.Dimensions = "ga:deviceCategory"; var requestData = request.Execute(); var labels = new List <string>(); var values = new List <double>(); foreach (var row in requestData.Rows) { labels.Add(row[0]); values.Add(double.Parse(row[1])); } var data = new ChartJSCore.Models.Data { Labels = labels }; var dataset = new PieDataset { Label = "Devices used", BackgroundColor = new List <string> { "#FF6384", "#36A2EB", "#FFCE56" }, HoverBackgroundColor = new List <string> { "#FF6384", "#36A2EB", "#FFCE56" }, Data = values }; data.Datasets = new List <Dataset> { dataset }; var chart = new Chart { Type = "pie", Data = data }; ViewBag.devices = chart; }
public Chart GenerateBubbleChart() { Chart chart = new Chart { Type = "bubble" }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); BubbleDataset dataset = new BubbleDataset() { Label = "Bubble Dataset", Data = new List <BubbleData>() }; BubbleData bubbleData1 = new BubbleData(); BubbleData 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 <string>() { "#FF6384" }; dataset.HoverBackgroundColor = new List <string>() { "#FF6384" }; chart.Data = data; return(chart); }
private async Task <Chart> GenerateGameChart() { var allGames = gameRepository.GetAll(); var allProfiles = dbContext.Users .Include(u => u.GameProfiles) .ThenInclude(gp => gp.Game) .SelectMany(u => u.GameProfiles) .ToList(); var usersPerGame = new Dictionary <string, int>(); foreach (var game in allGames) { var count = allProfiles .Count(p => p.Game.Id == game.Id); usersPerGame.Add(game.Name, count); } var chart = new Chart { Type = Enums.ChartType.PolarArea }; var data = new ChartJSCore.Models.Data { Labels = usersPerGame.Keys.ToList() }; var dataset = new PolarDataset { Label = "My dataset", BackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#FF6384"), ChartColor.FromHexString("#4BC0C0"), ChartColor.FromHexString("#FFCE56") }, Data = usersPerGame.Values.Select <int, double?>(i => i).ToList() }; data.Datasets = new List <Dataset> { dataset }; chart.Data = data; return(chart); }
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); }
public async Task <IActionResult> Graph(string address) { var graphData = await _blockchainService.GetGraphData(address); if (graphData.Succeeded) { Chart chart = new Chart(); chart.Type = "pie"; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); data.Labels = new List <string>(); var pieData = new List <double>(); var pieColors = new List <string>(); foreach (var item in graphData.Value) { data.Labels.Add(item.Address); pieData.Add(item.Donation); pieColors.Add(item.Color); } PieDataset dataset = new PieDataset() { Label = "Donatori", Data = pieData, BackgroundColor = pieColors, }; data.Datasets = new List <Dataset>(); data.Datasets.Add(dataset); chart.Data = data; ViewData["chart"] = chart; var response = await _blockchainService.GetCampaigns(); var model = new GraphInitViewModel { Campaigns = response.Value }; return(View(model)); } return(BadRequest()); }
public Chart GeneratePieChart(List <string> labels, PieDataset dataset) { Chart chart = new Chart { Type = "pie" }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data { Labels = labels }; data.Datasets = new List <Dataset> { dataset }; Options options = new Options() { Tooltips = new ToolTip() }; ToolTip toolTip = new ToolTip { Enabled = true, Mode = "single", Callbacks = new Callback { Label = "function(tooltipItem, data) { var indice = tooltipItem.index; return data.labels[indice] +': '+data.datasets[0].data[indice] + ' kWh';}" } }; options.Tooltips = toolTip; chart.Options = options; chart.Data = data; return(chart); }
private static Chart GetPercentagePerCountryChart(Dictionary <string, double> percentagePerCountry) { var chart = new Chart { Type = Enums.ChartType.Doughnut }; var data = new ChartJSCore.Models.Data { Labels = percentagePerCountry.Keys.ToList() }; var dataset = new PieDataset { Label = "# hours watched", Data = new List <double?>(percentagePerCountry.Values.Select(x => (double?)x)), BorderWidth = 1, BackgroundColor = new List <ChartColor>(), Type = Enums.ChartType.Doughnut, }; for (int i = 0; i < percentagePerCountry.Count; i++) { dataset.BackgroundColor.Add(ChartColor.CreateRandomChartColor(false)); } data.Datasets = new List <Dataset> { dataset }; chart.Data = data; chart.Options = new PieOptions { Responsive = true, MaintainAspectRatio = false, Title = new Title { Text = "Watched per country (in percentage)", Display = true }, ResponsiveAnimationDuration = 500 }; return(chart); }
private static Chart GetHourlyActivityChart(Dictionary <TimeSpan, double> timePerTimeOfDay) { var labels = timePerTimeOfDay.Keys.Select(x => x.IsFullHour() ? x.ToString("hh':'mm") : ""); var chart = new Chart { Type = Enums.ChartType.Radar }; var data = new ChartJSCore.Models.Data { Labels = labels.ToList() }; var dataset = new RadarDataset { Label = "# hours watched", Data = new List <double?>(timePerTimeOfDay.Values.Select(x => (double?)x)), BorderWidth = 1, BackgroundColor = ChartColor.FromRgba(229, 9, 20, 0.8), Type = Enums.ChartType.Radar }; data.Datasets = new List <Dataset> { dataset }; chart.Data = data; chart.Options = new RadarOptions { Responsive = true, MaintainAspectRatio = false, Title = new Title { Text = "Hours watched per time of day", Display = true }, ResponsiveAnimationDuration = 500, Tooltips = new ToolTip { Enabled = false } }; return(chart); }
public Chart GeneratePolarChart() { Chart chart = new Chart { Type = "polarArea" }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data { Labels = new List <string>() { "Red", "Green", "Yellow", "Grey", "Blue" } }; PolarDataset dataset = new PolarDataset() { Label = "My dataset", BackgroundColor = new List <string>() { "#FF6384", "#4BC0C0", "#FFCE56", "#E7E9ED", "#36A2EB" }, Data = new List <double>() { 11, 16, 7, 3, 14 } }; data.Datasets = new List <Dataset> { dataset }; chart.Data = data; return(chart); }
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); }
public Chart GetChartData(bool showMinTemp, bool showMaxTemp, bool showPrecipation, bool showThunder, string stationName, DateTime from, DateTime to) { var chart = new Chart(); chart.Type = "line"; var splitData = this.GetSplitData("0", stationName, from, to); ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); data.Labels = splitData.Select(x => "").ToList(); data.Datasets = new List <Dataset>(); if (showMinTemp) { data.Datasets.Add(this.GetChartDataset("0", splitData)); } if (showMaxTemp) { data.Datasets.Add(this.GetChartDataset("1", splitData)); } if (showPrecipation) { data.Datasets.Add(this.GetChartDataset("2", splitData)); } if (showThunder) { data.Datasets.Add(this.GetChartDataset("3", splitData)); } chart.Data = data; return(chart); }
public Chart GenerateLineChart() { Chart chart = new Chart { Type = "line" }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data { Labels = new List <string>() { "January", "February", "March", "April", "May", "June", "July" } }; LineDataset dataset = new LineDataset() { Label = "My First dataset", Data = new List <double>() { 65, 59, 80, 81, 56, 55, 40 }, Fill = false, LineTension = 0.1, BackgroundColor = "rgba(75, 192, 192, 0.4)", BorderColor = "rgba(75,192,192,1)", BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <string>() { "rgba(75,192,192,1)" }, PointBackgroundColor = new List <string>() { "#fff" }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <string>() { "rgba(75,192,192,1)" }, PointHoverBorderColor = new List <string>() { "rgba(220,220,220,1)" }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; data.Datasets = new List <Dataset> { dataset }; Options options = new Options() { Scales = new Scales() }; Scales scales = new Scales() { YAxes = new List <Object>() { new CartesianScale() } }; CartesianScale yAxes = new CartesianScale() { Ticks = new Tick() }; Tick 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); }
public IActionResult Index() { Chart chart = new Chart(); chart.Type = Enums.ChartType.Line; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); data.Labels = new List <string>() { "January", "February", "March", "April", "May", "June", "July" }; LineDataset dataset = new LineDataset() { Label = "My First dataset", Data = new List <double>() { 65, 59, 80, 81, 56, 55, 40 }, Fill = "false", LineTension = 0.1, BackgroundColor = "rgba(75, 192, 192, 0.4)", BorderColor = "rgba(75,192,192,1)", BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <string>() { "rgba(75,192,192,1)" }, PointBackgroundColor = new List <string>() { "#fff" }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <string>() { "rgba(75,192,192,1)" }, PointHoverBorderColor = new List <string>() { "rgba(220,220,220,1)" }, 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; ViewData["chart"] = chart; return(View()); }
/// <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 Chart TempChart() { var chart = new Chart(); chart.Type = Enums.ChartType.Line; var data = new ChartJSCore.Models.Data(); data.Labels = new List <string>(CityTemperatures.Keys); var dataset1 = new LineDataset() { Label = "Temperatures", Data = CityTemperatures.Values.ToList(), Fill = "true", LineTension = 0.1, BackgroundColor = "rgba(75, 192, 192, 0.4)", BorderColor = "rgba(75,192,192,1)", BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <string>() { "rgba(75,192,192,1)" }, PointBackgroundColor = new List <string>() { "#fff" }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <string>() { "rgba(75,192,192,1)" }, PointHoverBorderColor = new List <string>() { "rgba(220,220,220,1)" }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; var dataset2 = new LineDataset() { Label = "Median", Data = _medianTemps, Fill = "false", LineTension = 0.1, BackgroundColor = "rgba(0, 0, 0, 0.4)", BorderColor = "rgba(0,0,0,1)", BorderCapStyle = "butt", PointRadius = new List <int> { 0 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; data.Datasets = new List <Dataset> { dataset1, dataset2 }; 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 static Chart GenerateTempChart() { Chart chart = new Chart(); chart.Type = Enums.ChartType.Line; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); List <DateTime> labels = GetTempForecast().Select(e => e.dt).ToList(); List <string> shortLabels = labels.ConvertAll(x => x.ToString("ddd HH mm")); data.Labels = shortLabels; LineDataset dataset = new LineDataset() { Label = "Temperature", Data = GetTempForecast().Select(e => e.temperatureC).ToList(), LineTension = 0.5, BackgroundColor = "rgba(75, 192, 192, 0)", BorderColor = "rgba(244, 66, 66, 1)", BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <string>() { "rgba(244, 66, 66, 1)" }, PointBackgroundColor = new List <string>() { "#fff" }, PointBorderWidth = new List <int> { 3 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <string>() { "rgba(244, 66, 66, 1)" }, PointHoverBorderColor = new List <string>() { "rgba(220,220,220,1)" }, 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); Options options = new Options() { Scales = new Scales(), Legend = new Legend() { Labels = new LegendLabel() { BoxWidth = 0, FontSize = 18 } } }; Scales scale = new Scales() { }; TimeScale xAxes = new TimeScale() { Ticks = new Tick() }; Tick tick = new Tick() { FontColor = "rgba(244, 66, 66, 1)" }; CartesianScale yAxes = new CartesianScale() { Ticks = new CartesianLinearTick() { Max = 50, BeginAtZero = true, Callback = "function(value, index, values) {return value + ' °C' }" } }; xAxes.Ticks = tick; scale.YAxes = new List <Scale>() { yAxes }; scale.XAxes = new List <Scale>() { xAxes }; options.Scales = scale; chart.Options = options; chart.Data = data; return(chart); }
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); }
public Chart GetChart(ChartDataSet chartDataSets) { Chart chart = new Chart(); chart.Type = Enums.ChartType.Line; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); data.Datasets = new List <Dataset>(); data.Labels = chartDataSets.XValues; LineDataset dataset = new LineDataset() { Label = chartDataSets.Title, Data = chartDataSets.YValues.Select(x => (double?)Math.Round(x.Value, 2)).ToList(), Fill = "false", LineTension = 0.1, BackgroundColor = chartDataSets.Color, BorderColor = chartDataSets.Color, BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <ChartColor> { chartDataSets.Color }, PointBackgroundColor = new List <ChartColor> { ChartColor.FromHexString("#ffffff") }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <ChartColor> { chartDataSets.Color }, PointHoverBorderColor = new List <ChartColor> { chartDataSets.Color }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; data.Datasets.Add(dataset); chart.Data = data; return(chart); }
public async Task <ChartJSCore.Models.Chart> GetGraphData() { Random random = new Random(); ChartJSCore.Models.Chart chart = new ChartJSCore.Models.Chart(); chart.Type = "line"; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); data.Labels = (from contextShereRatese in _context.ShereRateses select contextShereRatese.DateTimeRates.ToLongTimeString()).Distinct().ToList(); data.Datasets = new List <Dataset>(); foreach (var companyCode in _context.Companies.Select(w => w.Code)) { string coloRround = "rbga(" + random.Next(0, 255) + "," + random.Next(0, 255) + "," + random.Next(0, 255); List <decimal> list = new List <decimal>(); foreach (decimal @decimal in (_context.ShereRateses.Where(w => w.Code == companyCode).Select( contextShereRatese => contextShereRatese.Rate))) { list.Add(@decimal); } LineDataset dataset = new LineDataset() { Label = companyCode, Data = list as IList <double>, Fill = "false", LineTension = 0.1, BackgroundColor = coloRround + ",0.4)", BorderColor = coloRround + ",1)", BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <string>() { coloRround + ",1)" }, PointBackgroundColor = new List <string>() { "#fff" }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <string>() { coloRround + ",1)" }, PointHoverBorderColor = new List <string>() { "rgba(220,220,220,1)" }, PointHoverBorderWidth = new List <int> { 2 }, PointRadius = new List <int> { 1 }, PointHitRadius = new List <int> { 10 }, SpanGaps = false }; data.Datasets.Add(dataset); } chart.Data = data; return(chart); }
public Chart GenerateLineScatterChart() { Chart chart = new Chart { Type = "line" }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); LineScatterDataset dataset = new LineScatterDataset() { Label = "Scatter Dataset", Data = new List <LineScatterData>() }; LineScatterData scatterData1 = new LineScatterData(); LineScatterData scatterData2 = new LineScatterData(); LineScatterData scatterData3 = new LineScatterData(); scatterData1.x = -10; scatterData1.y = 0; dataset.Data.Add(scatterData1); scatterData2.x = 0; scatterData2.y = 10; dataset.Data.Add(scatterData2); scatterData3.x = 10; scatterData3.y = 5; dataset.Data.Add(scatterData3); data.Datasets = new List <Dataset> { dataset }; chart.Data = data; Options options = new Options() { Scales = new Scales() }; Scales scales = new Scales() { XAxes = new List <Object>() { new CartesianScale() { Type = "linear", Position = "bottom", Ticks = new CartesianLinearTick() { BeginAtZero = true } } } }; options.Scales = scales; chart.Options = options; return(chart); }
public void createNewChart(List <string> ChartLabels, IList <double> ChartValues, string chartType, string ChartTitle, string ChartID) { Chart DateChart = new Chart(); DateChart.Type = chartType; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data(); data.Labels = ChartLabels; Options options = new Options() { Scales = new Scales() }; Scales scales = new Scales() { YAxes = new List <Object>() { new CartesianScale() { Type = "linear", Position = "bottom", Ticks = new CartesianLinearTick() { BeginAtZero = true } } } }; if (chartType != "pie") { options.Scales = scales; DateChart.Options = options; LineDataset dataset = new LineDataset() { Label = ChartTitle, Data = ChartValues, Fill = false, LineTension = 0.1, BackgroundColor = "rgba(75, 192, 192, 0.4)", BorderColor = "rgba(75,192,192,1)", BorderCapStyle = "butt", BorderDash = new List <int> { }, BorderDashOffset = 0.0, BorderJoinStyle = "miter", PointBorderColor = new List <string>() { "rgba(75,192,192,1)" }, PointBackgroundColor = new List <string>() { "#fff" }, PointBorderWidth = new List <int> { 1 }, PointHoverRadius = new List <int> { 5 }, PointHoverBackgroundColor = new List <string>() { "rgba(75,192,192,1)" }, PointHoverBorderColor = new List <string>() { "rgba(220,220,220,1)" }, 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); } else { PieDataset pie_dataset = new PieDataset() { Label = "My dataset", BackgroundColor = new List <string>() { "#FF6384", "#36A2EB", "#FFCE56" }, HoverBackgroundColor = new List <string>() { "#FF6384", "#36A2EB", "#FFCE56" }, Data = ChartValues }; data.Datasets = new List <Dataset>(); data.Datasets.Add(pie_dataset); } DateChart.Data = data; ViewData[ChartID] = DateChart; }
public Chart GenerateRadarChart() { Chart chart = new Chart { Type = "radar" }; ChartJSCore.Models.Data data = new ChartJSCore.Models.Data { Labels = new List <string>() { "Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running" } }; RadarDataset dataset1 = new RadarDataset() { Label = "My First dataset", BackgroundColor = "rgba(179,181,198,0.2)", BorderColor = "rgba(179,181,198,1)", PointBackgroundColor = new List <string>() { "rgba(179,181,198,1)" }, PointBorderColor = new List <string>() { "#fff" }, PointHoverBackgroundColor = new List <string>() { "#fff" }, PointHoverBorderColor = new List <string>() { "rgba(179,181,198,1)" }, Data = new List <double>() { 65, 59, 80, 81, 56, 55, 40 } }; RadarDataset dataset2 = new RadarDataset() { Label = "My Second dataset", BackgroundColor = "rgba(255,99,132,0.2)", BorderColor = "rgba(255,99,132,1)", PointBackgroundColor = new List <string>() { "rgba(255,99,132,1)" }, PointBorderColor = new List <string>() { "#fff" }, PointHoverBackgroundColor = new List <string>() { "#fff" }, PointHoverBorderColor = new List <string>() { "rgba(255,99,132,1)" }, Data = new List <double>() { 28, 48, 40, 19, 96, 27, 100 } }; data.Datasets = new List <Dataset> { dataset1, dataset2 }; chart.Data = data; return(chart); }