Beispiel #1
0
        private static Chart GenerateNestedDoughnutChart(List <Project> listOfProjects)
        {
            Chart chart = new Chart();

            chart.Type = Enums.ChartType.Doughnut;

            Data data = new Data();

            data.Labels = new List <string>()
            {
                "resource-group-1",
                "resource-group-2",
                "Data Services - Basic Database Days",
                "Data Services - Basic Database Days",
                "Azure App Service - Basic Small App Service Hours",
                "resource-group-2 - Other"
            };

            PieDataset outerDataset = new PieDataset()
            {
                BackgroundColor = new List <ChartColor>()
                {
                    ChartColor.FromHexString("#3366CC"),
                    ChartColor.FromHexString("#DC3912"),
                    ChartColor.FromHexString("#FF9900"),
                    ChartColor.FromHexString("#109618"),
                    ChartColor.FromHexString("#990099"),
                    ChartColor.FromHexString("#3B3EAC")
                },
                HoverBackgroundColor = new List <ChartColor>()
                {
                    ChartColor.FromHexString("#3366CC"),
                    ChartColor.FromHexString("#DC3912"),
                    ChartColor.FromHexString("#FF9900"),
                    ChartColor.FromHexString("#109618"),
                    ChartColor.FromHexString("#990099"),
                    ChartColor.FromHexString("#3B3EAC")
                },
                Data = new List <double>()
                {
                    0.0,
                    0.0,
                    8.31,
                    10.43,
                    84.69,
                    0.84
                }
            };

            PieDataset innerDataset = new PieDataset()
            {
                BackgroundColor = new List <ChartColor>()
                {
                    ChartColor.FromHexString("#3366CC"),
                    ChartColor.FromHexString("#DC3912"),
                    ChartColor.FromHexString("#FF9900"),
                    ChartColor.FromHexString("#109618"),
                    ChartColor.FromHexString("#990099"),
                    ChartColor.FromHexString("#3B3EAC")
                },
                HoverBackgroundColor = new List <ChartColor>()
                {
                    ChartColor.FromHexString("#3366CC"),
                    ChartColor.FromHexString("#DC3912"),
                    ChartColor.FromHexString("#FF9900"),
                    ChartColor.FromHexString("#109618"),
                    ChartColor.FromHexString("#990099"),
                    ChartColor.FromHexString("#3B3EAC")
                },
                Data = new List <double>()
                {
                    8.31,
                    95.96
                }
            };

            data.Datasets = new List <Dataset>();
            data.Datasets.Add(outerDataset);
            data.Datasets.Add(innerDataset);

            chart.Data = data;

            return(chart);
        }
Beispiel #2
0
        private static Chart GenerateLineChart(List <Project> listOfProjects)
        {
            Chart chart = new Chart();

            chart.Type = Enums.ChartType.Line;

            Data data = new 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  = ChartColor.FromRgba(75, 192, 192, 0.4),
                BorderColor      = ChartColor.FromRgba(75, 192, 192, 1),
                BorderCapStyle   = "butt",
                BorderDash       = new List <int> {
                },
                BorderDashOffset = 0.0,
                BorderJoinStyle  = "miter",
                PointBorderColor = new List <ChartColor>()
                {
                    ChartColor.FromRgba(75, 192, 192, 1)
                },
                PointBackgroundColor = new List <ChartColor>()
                {
                    ChartColor.FromHexString("#fff")
                },
                PointBorderWidth = new List <int> {
                    1
                },
                PointHoverRadius = new List <int> {
                    5
                },
                PointHoverBackgroundColor = new List <ChartColor>()
                {
                    ChartColor.FromRgba(75, 192, 192, 1)
                },
                PointHoverBorderColor = new List <ChartColor>()
                {
                    ChartColor.FromRgba(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()
            };

            Scales scales = new Scales()
            {
                YAxes = new List <Scale>()
                {
                    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);
        }
Beispiel #3
0
        private static Chart GenerateRadarChart(List <Project> listOfProjects)
        {
            Chart chart = new Chart();

            chart.Type = Enums.ChartType.Radar;

            Data data = new Data();

            data.Labels = new List <string>()
            {
                "Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"
            };

            RadarDataset dataset1 = new RadarDataset()
            {
                Label                = "My First dataset",
                BackgroundColor      = ChartColor.FromRgba(179, 181, 198, 0.2),
                BorderColor          = ChartColor.FromRgba(179, 181, 198, 1),
                PointBackgroundColor = new List <ChartColor>()
                {
                    ChartColor.FromRgba(179, 181, 198, 1)
                },
                PointBorderColor = new List <ChartColor>()
                {
                    ChartColor.FromHexString("#fff")
                },
                PointHoverBackgroundColor = new List <ChartColor>()
                {
                    ChartColor.FromHexString("#fff")
                },
                PointHoverBorderColor = new List <ChartColor>()
                {
                    ChartColor.FromRgba(179, 181, 198, 1)
                },
                Data = new List <double>()
                {
                    65, 59, 80, 81, 56, 55, 40
                }
            };

            RadarDataset dataset2 = new RadarDataset()
            {
                Label                = "My Second dataset",
                BackgroundColor      = ChartColor.FromRgba(255, 99, 132, 0.2),
                BorderColor          = ChartColor.FromRgba(255, 99, 132, 1),
                PointBackgroundColor = new List <ChartColor>()
                {
                    ChartColor.FromRgba(255, 99, 132, 1)
                },
                PointBorderColor = new List <ChartColor>()
                {
                    ChartColor.FromHexString("#fff")
                },
                PointHoverBackgroundColor = new List <ChartColor>()
                {
                    ChartColor.FromHexString("#fff")
                },
                PointHoverBorderColor = new List <ChartColor>()
                {
                    ChartColor.FromRgba(255, 99, 132, 1)
                },
                Data = new List <double>()
                {
                    28, 48, 40, 19, 96, 27, 100
                }
            };

            data.Datasets = new List <Dataset>();
            data.Datasets.Add(dataset1);
            data.Datasets.Add(dataset2);

            chart.Data = data;

            return(chart);
        }
Beispiel #4
0
        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());
        }
        public void FromHexString_Throws_FormatException_Invalid_Hex_Character()
        {
            string invalidHexString = "#12abex";

            Assert.Throws <FormatException>(() => ChartColor.FromHexString(invalidHexString));
        }
        public void FromHexString_Throws_FormatException_Without_Hex_Specifier()
        {
            string hexString = "12abef";

            Assert.Throws <FormatException>(() => ChartColor.FromHexString(hexString));
        }
Beispiel #7
0
        //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());
        }
Beispiel #8
0
        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);
        }