Hi,
I am trying to create a Leave chart for the employees in the company. I am having some problems in grouping data in Telerik Gantt chart. The datasource that is fed to the chart is shown below.
MemberID MemberName StartDate EndDate
----------------------------------------------------------------------------------------
1 Name1 30987 31723
2 Name1 31908 31999
3 Name2 35678 36321
4 Name3 34245 34909
etc...
I want to display the member names on one axis, and the dates on the other axis. If you notice, Name1 has two records, so this should be reflected in the chart by showing two bars for one name (name1). I am getting the correct chart without grouping (however if a member has two leave periods, his name will be shown twice). Unfortunately with grouping, I am not being able to get the results printed on the chart as required. The code I am using is shown below. I am creating two series (assuming that a user has a maximum of two leave periods, so that the group column will divide each leave period on a separate series).
I am using version 2.0.0 of Telerik Controls.
//*********************************************************************************************************
// YAxis Properties
radChart.YAxis.ValueFormat =
ChartValueFormat.ShortDate;
radChart.YAxis.LabelRotationAngle = 90;
radChart.YAxis.Label.Visible =
true;
radChart.YAxis.AutoScale =
false;
radChart.YAxis.IsZeroBased =
false;
radChart.YAxis.AddRange(_from.ToOADate(), _maxDate.Value.ToOADate(), 1);
// YAxis2 Properties
radChart.YAxis2.ValueFormat =
ChartValueFormat.ShortDate;
radChart.YAxis2.LabelRotationAngle = 90;
radChart.YAxis2.Label.Visible =
true;
radChart.YAxis2.AutoScale =
false;
radChart.YAxis2.IsZeroBased =
false;
radChart.YAxis2.Visible =
AxisVisibility.True;
radChart.YAxis2.AddRange(_from.ToOADate(), _maxDate.Value.ToOADate(), 1);
// General Properties
radChart.DefaultType =
ChartSeriesType.Gantt;
radChart.Legend.Visible =
false;
radChart.Titles.Add(
new ChartTitle("NBK WDG Leave Chart"));
// add data to table
DataTable _table = new DataTable("Leave");
_table.Columns.Add(
"MemberId", typeof(Int32));
_table.Columns.Add(
"MemberName", typeof(String));
_table.Columns.Add(
"StartDate", typeof(Double));
_table.Columns.Add(
"EndDate", typeof(Double));
foreach (Member _member in Members)
{
_table.Rows.Add(_member.MemberId, _member.MemberName, _member.StartDate < _from ? _from.ToOADate() : _member.StartDate.ToOADate(), _member.EndDate.ToOADate());
}
// sort by member name
DataView _view = new DataView();
_view.Table = _table;
_view.Sort =
"MemberName";
// bind data to chart
radChart.DataSource = _view;
// instantiate new series
ChartSeries _series = new ChartSeries();
// define series Properties
_series.Type =
ChartSeriesType.Gantt;
_series.Name =
"Leave Periods";
_series.LabelAppearance.Visible =
false;
_series.DataYColumn =
"StartDate";
_series.DataYColumn2 =
"EndDate";
radChart.Series.Add(_series);
ChartSeries _series2 = new ChartSeries();
_series2.Type =
ChartSeriesType.Gantt;
_series2.Name =
"Leave Periods 2";
_series2.LabelAppearance.Visible =
false;
_series2.DataYColumn =
"StartDate";
_series2.DataYColumn2 =
"EndDate";
radChart.Series.Add(_series2);
radChart.SeriesOrientation =
ChartSeriesOrientation.Horizontal;
radChart.DataGroupColumn =
"MemberId";
// XAxis Properties
radChart.XAxis.DataLabelsColumn =
"MemberName";
radChart.XAxis.Label.Visible =
true;
// bind data
radChart.DataBind();
// show only weekly marks
int i = 1;
foreach (ChartAxisItem _item in radChart.YAxis.Items)
{
if ((i % 7) != 0)
{
_item.Visible =
false;
}
i++;
}
i = 1;
foreach (ChartAxisItem _item in radChart.YAxis2.Items)
{
if ((i % 7) != 0)
{
_item.Visible =
false;
}
i++;
}
Please help.
Regards,
Ehab