Ejemplo n.º 1
0
        public ChartJs GenerateChart(double percentage)
        {
            var chart = new ChartJs()
            {
                type = "doughnut",
                data = new Helpers.Data
                {
                    datasets = new Dataset[]
                    {
                        new Dataset
                        {
                            label           = "BudgetUsed",
                            data            = new float[] { float.Parse(percentage.ToString()), float.Parse((100 - percentage).ToString()) },
                            backgroundColor = new string[] { "#ff004c", "#e6e6e6" },
                            borderColor     = "#fff",
                        }
                    },
                    labels = new string[] { "Used", "Left" },
                },
                options = new Options
                {
                    responsive          = true,
                    maintainAspectRatio = true,
                    legend = new Legend
                    {
                        display = false
                    },
                    title = new Title
                    {
                        display = false
                    },
                    cutoutPercentage = 80
                }
            };

            return(chart);
        }
Ejemplo n.º 2
0
        public IViewComponentResult Invoke()
        {
            //  var chart = JsonConvert.DeserializeObject<ChartJs> (chartData);

            Ticks ticks = new Ticks {
                beginAtZero = true
            };
            Yax yax = new Yax {
                ticks = ticks
            };

            Yax[] y = new Yax[1];
            y[0] = yax;
            Scales scales = new Scales();

            scales.yAxes = y;

            Data data = new Data();

            YearlySaleData saleData = GetYearlySaleData();

            Dataset dataset = new Dataset
            {
                borderWidth     = 1,
                label           = "Yearly Sale",
                data            = saleData.Amount.ToArray(),
                backgroundColor = new 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(54, 162, 235, 0.2)",
                    "rgba(255, 203, 83, 0.2)",
                    "rgba(255, 159, 64, 0.2)"
                },
                borderColor = new 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, 203, 83, 1)",
                    "rgba(153, 102, 255, 1)",
                    "rgba(255, 203, 83, 1)",
                    "rgba(255, 159, 64, 1)"
                }
            };

            ChartJs chart = new ChartJs
            {
                type       = "bar",
                responsive = true,
                options    = new Options {
                    scales = scales
                },
                data = new Data {
                    datasets = new Dataset[] { dataset }, labels = saleData.Year.ConvertAll <string>(delegate(int i) { return(i.ToString()); }).ToArray()
                }
            };

            var chartModel = new ChartJsViewModel
            {
                Chart     = chart,
                ChartJson = JsonConvert.SerializeObject(chart, new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                })
            };

            return(View(chartModel));
        }
Ejemplo n.º 3
0
        // [ServiceFilter(typeof(KlantFilter))]
        // [Authorize]
        public IViewComponentResult Invoke()
        {
            // Ref: https://www.chartjs.org/docs/latest/

            Klant klant = (Klant)_klantenRepo.GetByEmail(HttpContext.User.Identity.Name);



            string[] dataLabels2 = new string[6];
            int[]    data        = { 0, 0, 0, 0, 0, 0 };
            DateTime date        = DateTime.Today;
            DateTime date2;

            for (int i = 5; i >= 0; i--)
            {
                date2          = date.AddDays(-7);
                dataLabels2[i] = string.Format("{0:dd/MM/yy}", date2) + "-" + string.Format("{0:dd/MM/yy}", date);
                foreach (Contract c in klant.Contracten)
                {
                    foreach (Ticket t in c.Tickets)
                    {
                        if (t.AanmaakDatum <= date)
                        {
                            if (t.DatumAfgewerkt.Equals(null) || t.DatumAfgewerkt >= date2)
                            {
                                data[i] += 1;
                            }
                        }
                    }
                }

                date = date2.AddDays(-1);
            }

            string[] backgroundColor =
            {
                "rgba(204, 214, 12, 0.2)",
                "rgba(204, 214, 12, 0.2)",
                "rgba(204, 214, 12, 0.2)",
                "rgba(204, 214, 12, 0.2)",
                "rgba(204, 214, 12, 0.2)",
                "rgba(204, 214, 12, 0.2)"
            };

            Dataset dataset = new Dataset {
                label = "Actieve tickets", data = data, borderWidth = 1, backgroundColor = backgroundColor
            };

            Dataset[] datasets = { dataset };


            ChartJs Chart = new ChartJs
            {
                type       = "line",
                responsive = true,
                data       = new Models.Chart.Data
                {
                    labels   = dataLabels2,
                    datasets = datasets
                },
            };

            var chartModel = new ChartJsViewModel
            {
                Chart     = Chart,
                ChartJson = JsonConvert.SerializeObject(Chart, new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore,
                })
            };

            return(View(chartModel));
        }
Ejemplo n.º 4
0
        public IViewComponentResult Invoke()
        {
            //  var chart = JsonConvert.DeserializeObject<ChartJs> (chartData);

            Ticks ticks = new Ticks {
                beginAtZero = true
            };
            Yax yax = new Yax {
                ticks = ticks
            };

            Yax[] y = new Yax[1];
            y[0] = yax;
            Scales scales = new Scales();

            scales.yAxes = y;

            Data data = new Data();

            StaffSale saleData = GetStaffSaleData();

            Dataset datasetY = new Dataset
            {
                borderWidth     = 1,
                label           = "Yearly",
                data            = saleData.YearWise.ToArray(),
                backgroundColor = new 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(54, 162, 235, 0.2)",
                    "rgba(255, 203, 83, 0.2)",
                    "rgba(255, 159, 64, 0.2)",
                    //"rgba(255, 99, 132, 0.2)",
                    //"rgba(54, 162, 235, 0.2)",
                    //"rgba(255, 206, 86, 0.2)",
                    //"rgba(75, 192, 192, 0.2)",
                },
                borderColor = new 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, 203, 83, 1)",
                    "rgba(255, 159, 64, 1)",
                    "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)",
                }
            };
            Dataset datasetM = new Dataset
            {
                borderWidth     = 1,
                label           = "Monthly",
                data            = saleData.MonthWise.ToArray(),
                backgroundColor = new 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(54, 162, 235, 0.2)",
                    "rgba(255, 203, 83, 0.2)",
                    // "rgba(255, 159, 64, 0.2)",
                    //  "rgba(255, 99, 132, 0.2)",
                    "rgba(54, 162, 235, 0.2)",
                    "rgba(255, 206, 86, 0.2)",
                    //"rgba(75, 192, 192, 0.2)",
                },
                borderColor = new 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, 203, 83, 1)",
                    "rgba(255, 159, 64, 1)",
                    //"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)",
                }
            };
            Dataset datasetC = new Dataset
            {
                borderWidth     = 1,
                label           = "Today",
                data            = saleData.CurrentWise.ToArray(),
                backgroundColor = new 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(54, 162, 235, 0.2)",
                    "rgba(255, 203, 83, 0.2)",
                    "rgba(255, 159, 64, 0.2)",
                    "rgba(255, 99, 132, 0.2)",
                    // "rgba(54, 162, 235, 0.2)",
                    //"rgba(255, 206, 86, 0.2)",
                    // "rgba(75, 192, 192, 0.2)",
                },
                borderColor = new 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, 203, 83, 1)",
                    //"rgba(255, 159, 64, 1)",
                    "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)",
                }
            };
            ChartJs chart = new ChartJs
            {
                type       = "bar",
                responsive = true,
                options    = new Options {
                    scales = scales, title = new Title {
                        Display = true, Text = "Staff Sale"
                    }, legend = new Legend {
                        Position = "Top"
                    }
                },
                data = new Data {
                    datasets = new Dataset[] { datasetY, datasetM, datasetC }, labels = saleData.StaffName.ToArray()
                }
            };

            var chartModel = new ChartJsViewModel
            {
                Chart     = chart,
                ChartJson = JsonConvert.SerializeObject(chart, new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                })
            };

            return(View(chartModel));
        }