Beispiel #1
0
		public static Highcharts EmployeePieChart(this IEnumerable<DepartmentVM> departments, DepartmentChartGroupOption groupOption)
		{
			var dataPoints = new Point[0];

			switch (groupOption)
			{
				case DepartmentChartGroupOption.Department:
					var orderedDepartments = departments.OrderBy(x => x.Name).ToList();
					dataPoints = orderedDepartments.Select(x => new Point { Name = x.Name, Y = x.EmployeeCount }).ToArray();
					break;
				case DepartmentChartGroupOption.DepartmentGroup:
					var orderedGroups = departments.GroupBy(x => x.GroupName).OrderBy(x => x.Key).ToList();
					dataPoints = orderedGroups.Select(x => new Point { Name = x.Key, Y = x.Sum(y => y.EmployeeCount) }).ToArray();
					break;
			}

			return new Highcharts("department_employees") //this name becomes the div id, so it needs to be one word!!!
				.InitChart(new Chart { PlotShadow = false })
				.SetTitle(new Title { Text = "Departments" })
				.SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.y; }" }) //everything needs to be small case
				.SetPlotOptions(new PlotOptions
					{
						Pie = new PlotOptionsPie
							{
								AllowPointSelect = true,
								Cursor = Cursors.Pointer,
								DataLabels = new PlotOptionsPieDataLabels
									{
										Color = ColorTranslator.FromHtml("#000000"),
										ConnectorColor = ColorTranslator.FromHtml("#000000"),
										Formatter = "function() { return this.point.name; }"
									}
							}
					})
				.SetSeries(new Series
					{
						Type = ChartTypes.Pie,
						Name = "Browser share",
						Data = new Data(dataPoints)
					});
		}
Beispiel #2
0
		public static Highcharts EmployeeBarChart(this IEnumerable<DepartmentVM> departments, DepartmentChartGroupOption groupOption)
		{
			var categories = new string[0];
			var dataPoints = new Point[0];
			switch (groupOption)
			{
				case DepartmentChartGroupOption.Department:
					var orderedDepartments = departments.OrderBy(x => x.Name).ToList();
					categories = orderedDepartments.Select(x => x.Name).ToArray();
					dataPoints = orderedDepartments.Select(x => new Point { Name = x.Name, Y = x.EmployeeCount }).ToArray();
					break;
				case DepartmentChartGroupOption.DepartmentGroup:
					var orderedGroups = departments.GroupBy(x => x.GroupName).OrderBy(x => x.Key).ToList();
					categories = orderedGroups.Select(x => x.Key).ToArray();
					dataPoints = orderedGroups.Select(x => new Point { Name = x.Key, Y = x.Sum(y => y.EmployeeCount) }).ToArray();
					break;
			}

			return new Highcharts("departments") //this name becomes the div id, so it needs to be one word!!!
				.InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
				.SetXAxis(new XAxis { Categories = categories })
				.SetYAxis(new YAxis { Min = 0, Title = new YAxisTitle { Text = "Employees" } })
				.SetLegend(new Legend
					{
						Layout = Layouts.Vertical,
						Align = HorizontalAligns.Left,
						VerticalAlign = VerticalAligns.Top,
						X = 100,
						Y = 70,
						Floating = true,
						//BackgroundColor = ColorTranslator.FromHtml("#FFFFFF"),
						Shadow = true
					})
				.SetTooltip(new Tooltip { Formatter = @"function() { return ''+ this.x +': '+ this.y; }" })
				.SetPlotOptions(new PlotOptions
					{
						Column = new PlotOptionsColumn
							{
								PointPadding = 0.2,
								BorderWidth = 0
							}
					})
				.SetSeries(new Series
					{
						Name = "Employee count",
						Data = new Data(dataPoints)
					});

		}
		public PartialViewResult DepartmentEmployeesPieChart(DepartmentChartGroupOption groupOption = DepartmentChartGroupOption.Department)
        {
            return PartialView("_Highchart", DepartmentViewModels.EmployeePieChart(groupOption));
        }
		public async Task<ViewResult> IndexAsync(DepartmentChartGroupOption groupOption = DepartmentChartGroupOption.Department)
		{
			return View("HumanResource", await Task.Run(() => DepartmentViewModels.EmployeePieChart(groupOption)));
		}