| void RadChart1_ItemDataBound(object sender, ChartItemDataBoundEventArgs e) |
| { |
| DataRowView drv = e.DataItem as DataRowView; |
| DateTime startDate = (DateTime)drv["EventDate"]; |
| DateTime endDate = (DateTime)drv["EndDate"]; |
| StringBuilder sb = new StringBuilder(); |
| sb.Append(drv["Title"].ToString()); |
| sb.AppendFormat("\n{0} - {1}", startDate.ToShortDateString(), endDate.ToShortDateString()); |
| e.SeriesItem.Name = drv["Source"].ToString(); |
| e.SeriesItem.ActiveRegion.Tooltip = sb.ToString(); |
| } |
Basic theory: I'm grabbing list items from various SharePoint lists via Lists Web service, converting the XmlNodes into DataSets, doing a little manipulation to the data, then create a DataTable with all List items.
DataTable schema looks like:
| dt.Columns.Add("Source", typeof(String)); |
| dt.Columns.Add("Title", typeof(string)); |
| dt.Columns.Add("From", typeof(double)); |
| dt.Columns.Add("To", typeof(double)); |
| dt.Columns.Add("EventDate", typeof(DateTime)); |
| dt.Columns.Add("EndDate", typeof(DateTime)); |
For each Source, I want it to show up in different colors for the Gantt chart and display the name so the user knows which list it came from.
Snippet for chart:
| ChartSeries series = new ChartSeries(); |
| RadChart1.PlotArea.YAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.ShortDate; |
| RadChart1.PlotArea.YAxis.Appearance.LabelAppearance.RotationAngle = 45; |
| RadChart1.PlotArea.YAxis.LabelStep = 1; |
| RadChart1.PlotArea.YAxis.Appearance.LabelAppearance.Position.AlignedPosition = Telerik.Charting.Styles.AlignedPositions.Top; |
| RadChart1.Series.Clear(); |
| RadChart1.PlotArea.YAxis.AutoScale = false; |
| RadChart1.PlotArea.YAxis.AxisMode = ChartYAxisMode.Extended; |
| DataTable dt = getListItems(); |
| RadChart1.PlotArea.YAxis.AddRange(from.ToOADate(), to.ToOADate(), step); |
| RadChart1.DataSource = dt; |
| series.Type = ChartSeriesType.Gantt; |
| series.Appearance.LabelAppearance.Visible = false; |
| series.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.SeriesName; |
| series.Appearance.BarWidthPercent = 30M; |
| series.DataYColumn = "From"; |
| series.DataYColumn2 = "To"; |
| RadChart1.Series.Add(series); |
| RadChart1.SeriesOrientation = ChartSeriesOrientation.Horizontal; |
| RadChart1.ChartTitle.TextBlock.Text = "Aggregated Calendar"; |
| if(_realWidth > 0) |
| RadChart1.Width = new Unit(_realWidth * .97); |
| RadChart1.DataBind(); |
Here is the ItemDataBound event:
| void RadChart1_ItemDataBound(object sender, ChartItemDataBoundEventArgs e) |
| { |
| DataRowView drv = e.DataItem as DataRowView; |
| DateTime startDate = (DateTime)drv["EventDate"]; |
| DateTime endDate = (DateTime)drv["EndDate"]; |
| StringBuilder sb = new StringBuilder(); |
| sb.Append(drv["Title"].ToString()); |
| sb.AppendFormat("\n{0} - {1}", startDate.ToShortDateString(), endDate.ToShortDateString()); |
| e.SeriesItem.Name = drv["Source"].ToString(); |
| e.SeriesItem.ActiveRegion.Tooltip = sb.ToString(); |
| } |
I would expect to be able to set the column that is being used for the Series like
| series.DataSeriesColumn = "Source"; //DataTable column name |
Surely, I don't have to create new ChartSeries objects for every list I aggregate? Any help would be appreciated.