Esempio n. 1
0
        /// <summary>
        /// Generates the chart for the day
        /// </summary>
        /// <param name="date">The start date</param>
        /// <param name="chartName">The title for the chart</param>
        /// <returns>The day chart</returns>
        private Highcharts GenerateDayChart(DateTime date, string chartName)
        {
            var slots = slotService.GetSlots();

            //modify data type to make it of array type
            var chartData = new List <ChartData>();

            foreach (wrapper.Slot slot in slots)
            {
                chartData.Add(new ChartData
                {
                    yCategories = slot.Time,
                    Frequency   = (int)(service.CalculateSlotFrequencyRate(date, slot.SlotId) * 100),
                    Occupancy   = (int)(service.CalculateSlotOccupancyRate(date, slot.SlotId) * 100),
                    Utilisation = (int)(service.CalculateSlotUtilisationRate(date, slot.SlotId) * 100)
                });
            }
            ;

            var xData = chartData.Select(i => i.yCategories).ToArray();

            var yDataFrequency = chartData.Select(i => new object[] { i.Frequency }).ToArray();

            var yDataOccupancy = chartData.Select(i => new object[] { i.Occupancy }).ToArray();

            var yDataUtilisation = chartData.Select(i => new object[] { i.Utilisation }).ToArray();

            //instanciate an object of the Highcharts type
            var dayChart = new Highcharts(chartName)
                           //define the type of chart
                           .InitChart(new DotNet.Highcharts.Options.Chart {
                DefaultSeriesType = ChartTypes.Line
            })
                           //overall Title of the chart
                           .SetTitle(new Title {
                Text = "Rates for " + date.ToShortDateString()
            })
                           //small label below the main Title
                           .SetSubtitle(new Subtitle {
                Text = "Frequency, Occupancy and Utilisation"
            })
                           //load the X values
                           .SetXAxis(new XAxis {
                Categories = xData, Min = 0
            })
                           //set the Y title
                           .SetYAxis(new YAxis {
                Title = new YAxisTitle {
                    Text = "Rate %"
                }
            })
                           .SetTooltip(new Tooltip
            {
                Enabled   = true,
                Formatter = "function() { return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y; }"
            })
                           .SetPlotOptions(new PlotOptions
            {
                Line = new PlotOptionsLine
                {
                    DataLabels = new PlotOptionsLineDataLabels
                    {
                        Enabled = true
                    },
                    EnableMouseTracking = false
                }
            })
                           //load the Y values
                           .SetSeries(new[]
            {
                //line colours changed to make the dashbaord consistent
                new Series {
                    Name = "Frequency", Data = new Data(yDataFrequency), Color = Color.Turquoise
                },
                new Series {
                    Name = "Occupancy", Data = new Data(yDataOccupancy), Color = Color.DeepPink
                },
                new Series {
                    Name = "Utilisation", Data = new Data(yDataUtilisation), Color = Color.DarkOrange
                },
            });

            return(dayChart);
        }