using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Drawing;
using
System.Data;
using
Telerik.Web.UI;
namespace
TestApp.WebSite
{
public
partial
class
TestChart : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
DrawChart();
}
}
private
void
DrawChart()
{
try
{
DateTime endDate = DateTime.Now;
DateTime startDate = endDate.AddDays(-30);
MonthlyViewChart.ChartTitle.Text =
string
.Format(
"Monthly Sales Report - {0} to {1}"
, startDate.ToShortDateString(), endDate.ToShortDateString());
Dictionary<
int
, Color> seriesItemColor =
new
Dictionary<
int
, Color> { { 0, Color.FromArgb(0, 103, 56) }, { 1, Color.FromArgb(39, 170, 226) }, { 2, Color.FromArgb(191, 30, 46) }, { 3, Color.FromArgb(43, 182, 115) }, { 4, Color.FromArgb(142, 198, 63) }, { 5, Color.FromArgb(242, 90, 41) }, { 6, Color.FromArgb(43, 57, 145) }, { 7, Color.FromArgb(146, 39, 143) }, { 8, Color.FromArgb(238, 43, 122) }, { 9, Color.FromArgb(248, 237, 51) }, { 10, Color.FromArgb(0, 167, 157) }, { 11, Color.FromArgb(102, 46, 145) }, { 12, Color.FromArgb(252, 176, 64) }, { 13, Color.FromArgb(214, 223, 34) }, { 14, Color.FromArgb(158, 31, 100) }, { 15, Color.FromArgb(139, 119, 101) }, { 16, Color.FromArgb(99, 184, 255) }, { 17, Color.FromArgb(139, 87, 66) }, { 18, Color.FromArgb(139, 139, 0) }, { 19, Color.FromArgb(240, 128, 128) } };
MonthlyViewChart.PlotArea.Series.Clear();
MonthlyViewChart.PlotArea.XAxis.Items.Clear();
List<Department> departmentReports =
new
Department().MonthlySales();
//Create a DataTable with two columns
DataTable tbl =
new
DataTable();
tbl.Columns.Add(
new
DataColumn(
"DepartmentName"
));
int
j = 0;
Enumerable.Range(0, departmentReports.Count).ToList().ForEach(x =>
{
tbl.Rows.Add();
tbl.Rows[j][
"DepartmentName"
] = departmentReports[j].DepartmentName;
j++;
});
MonthlyViewChart.PlotArea.XAxis.DataLabelsField =
"DepartmentName"
;
int
i = 0;
foreach
(var report
in
departmentReports)
{
ColumnSeries series =
new
ColumnSeries();
series.Name = report.DepartmentName;
series.Appearance.FillStyle.BackgroundColor = seriesItemColor.Where(x => x.Key == i).FirstOrDefault().Value;
series.TooltipsAppearance.BackgroundColor = Color.White;
series.LabelsAppearance.Visible =
false
;
//Create columns used for DataFieldY and ClientTemplate properties
string
currDSColumn =
"DataSourceColumn"
+ i;
string
tooltipColumn =
"ToolTipColumn"
+ i;
tbl.Columns.Add(
new
DataColumn(currDSColumn));
tbl.Columns.Add(
new
DataColumn(tooltipColumn));
series.DataFieldY = currDSColumn;
series.TooltipsAppearance.ClientTemplate =
"#=dataItem."
+ tooltipColumn +
"#"
;
MonthlyViewChart.PlotArea.Series.Add(series);
//Fill values for Series YValues and ToolTips
tbl.Rows[i][currDSColumn] = report.SalesPercentage;
tbl.Rows[i][tooltipColumn] =
string
.Format(
" Number of Employees: {0} <br /> Possible Sales: {1} <br /> Actual Sales: {2} "
, report.NumberOfEmployees, report.NumberOfGoods, report.Sold);
i++;
}
MonthlyViewChart.DataSource = tbl;
MonthlyViewChart.DataBind();
}
catch
(Exception ex)
{
Response.Write(ex.Message);
}
}
}
public
class
Department
{
public
int
SalesPercentage {
get
;
set
; }
public
int
Sold {
get
;
set
; }
public
string
DepartmentName {
get
;
set
; }
public
int
NumberOfGoods {
get
;
set
; }
public
int
NumberOfEmployees {
get
;
set
; }
public
Department()
{
}
public
List<Department> MonthlySales()
{
List<Department> list =
new
List<Department>();
list.Add(
new
Department { DepartmentName =
"Department 1"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 2"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 3"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 4"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 5"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 6"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 7"
, NumberOfEmployees = 1, NumberOfGoods = 90, SalesPercentage = 22, Sold = 20 });
list.Add(
new
Department { DepartmentName =
"Department 8"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 9"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 10"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 11"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 12"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 13"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 14"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
list.Add(
new
Department { DepartmentName =
"Department 15"
, NumberOfEmployees = 0, NumberOfGoods = 0, SalesPercentage = 0, Sold = 0 });
return
list.OrderBy(x => x.DepartmentName).ToList();
}
}
}