| 1 |
public Form1() |
| 2 |
{ |
| 3 |
InitializeComponent(); |
| 4 |
} |
| 5 |
|
| 6 |
protected override void OnLoad(EventArgs e) |
| 7 |
{ |
| 8 |
base.OnLoad(e); |
| 9 |
|
| 10 |
DateTime today = DateTime.Today; |
| 11 |
|
| 12 |
// Setup chart orientation |
| 13 |
this.radChart1.SeriesOrientation = ChartSeriesOrientation.Horizontal; |
| 14 |
|
| 15 |
// Setup XAxis |
| 16 |
this.radChart1.PlotArea.XAxis.IsZeroBased = false; |
| 17 |
this.radChart1.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.ShortDate; |
| 18 |
this.radChart1.PlotArea.XAxis.AutoScale = false; |
| 19 |
this.radChart1.PlotArea.XAxis.AddRange(today.ToOADate(), today.AddDays(10).ToOADate(), 1); |
| 20 |
this.radChart1.PlotArea.XAxis.LayoutMode = Telerik.Charting.Styles.ChartAxisLayoutMode.Inside; |
| 21 |
|
| 22 |
// Setup YAxis |
| 23 |
this.radChart1.PlotArea.YAxis.IsZeroBased = false; |
| 24 |
this.radChart1.PlotArea.YAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.ShortTime; |
| 25 |
this.radChart1.PlotArea.YAxis.AutoScale = false; |
| 26 |
this.radChart1.PlotArea.YAxis.AddRange(today.AddHours(7).ToOADate(), today.AddHours(18).ToOADate(), 1d / 24d); |
| 27 |
|
| 28 |
// Setup Series |
| 29 |
this.radChart1.Series[0].Type = ChartSeriesType.Gantt; |
| 30 |
this.radChart1.Series[0].DataXColumn = "X"; |
| 31 |
this.radChart1.Series[0].DataXColumn2 = "X2"; |
| 32 |
this.radChart1.Series[0].DataYColumn = "Y"; |
| 33 |
this.radChart1.Series[0].DataYColumn2 = "Y2"; |
| 34 |
|
| 35 |
// Data Bind |
| 36 |
this.radChart1.Series[0].Appearance.LabelAppearance.Visible = false; |
| 37 |
this.radChart1.DataSource = GenerateSource("Table"); |
| 38 |
this.radChart1.DataMember = "Table"; |
| 39 |
this.radChart1.DataBind(); |
| 40 |
} |
| 41 |
|
| 42 |
private DataSet GenerateSource(string tableName) |
| 43 |
{ |
| 44 |
|
| 45 |
double[,] input = new double[3, 2] { |
| 46 |
{ 8, 12 }, { 9, 14}, { 13, 18.5} |
| 47 |
}; |
| 48 |
|
| 49 |
DataTable table = new DataTable(tableName); |
| 50 |
table.Columns.Add("X", typeof(double)); |
| 51 |
table.Columns.Add("X2", typeof(double)); |
| 52 |
table.Columns.Add("Y", typeof(double)); |
| 53 |
table.Columns.Add("Y2", typeof(double)); |
| 54 |
|
| 55 |
DateTime start = DateTime.Today; |
| 56 |
|
| 57 |
for (int i = 0; i < 3; i++) |
| 58 |
{ |
| 59 |
DataRow row = table.NewRow(); |
| 60 |
|
| 61 |
row["X"] = start.AddDays(i).ToOADate(); |
| 62 |
row["X2"] = start.AddDays(i + 1).ToOADate(); |
| 63 |
row["Y"] = start.AddHours(input[i, 0]).ToOADate(); |
| 64 |
row["Y2"] = start.AddHours(input[i, 1]).ToOADate(); |
| 65 |
|
| 66 |
table.Rows.Add(row); |
| 67 |
} |
| 68 |
|
| 69 |
DataSet dataSet = new DataSet(); |
| 70 |
dataSet.Tables.Add(table); |
| 71 |
return dataSet; |
| 72 |
} |