Hi, I need to be able to separately set the color of each of the bars in a Gantt chart.
I have managed to use the custom palette but this seems to change all of the bars in a series to the same color, I need to be able to change the color of each bar. Can this be done?
I have seen mention of using a GanttSeries, in which fine tuning of the bar attributes can be undertaken, but can find no examples of how to use this, help would be appreciated.
The code I have used is below: cht.GanttChart.Columns.SeriesLabelsColumnIndex = 0 cht.GanttChart.Columns.ItemLabelsColumnIndex = 1 cht.GanttChart.Columns.StartTimeColumnIndex = 2 cht.GanttChart.Columns.EndTimeColumnIndex = 3 cht.GanttChart.Columns.IDColumnIndex = 4 cht.GanttChart.Columns.LinkToColumnIndex = 5 cht.GanttChart.Columns.PercentCompleteColumnIndex = 6 cht.GanttChart.Columns.OwnerColumnIndex = 7 Dim t1 As System.Drawing.Color Dim t2 As System.Drawing.Color t1 = Drawing.Color.Blue t2 = Drawing.Color.Yellow Dim ChartColors() As System.Drawing.Color = {t1, t2, t1, t2, t1, t2, t1, t1, t2, t1, t2, t1, t2, t1} Me.cht.ColorModel.ModelStyle = Infragistics.UltraChart.Shared.Styles.ColorModels.CustomLinear Me.cht.ColorModel.CustomPalette = ChartColors Me.cht.DataSource = sqlds Me.cht.DataBind()
The code I have used is below:
cht.GanttChart.Columns.SeriesLabelsColumnIndex = 0
cht.GanttChart.Columns.ItemLabelsColumnIndex = 1
cht.GanttChart.Columns.StartTimeColumnIndex = 2
cht.GanttChart.Columns.EndTimeColumnIndex = 3
cht.GanttChart.Columns.IDColumnIndex = 4
cht.GanttChart.Columns.LinkToColumnIndex = 5
cht.GanttChart.Columns.PercentCompleteColumnIndex = 6
cht.GanttChart.Columns.OwnerColumnIndex = 7
Dim t1 As System.Drawing.Color
Dim t2 As System.Drawing.Color
t1 = Drawing.Color.Blue
t2 = Drawing.Color.Yellow
Dim ChartColors() As System.Drawing.Color = {t1, t2, t1, t2, t1, t2, t1, t1, t2, t1, t2, t1, t2, t1}
Me.cht.ColorModel.ModelStyle = Infragistics.UltraChart.Shared.Styles.ColorModels.CustomLinear
Me.cht.ColorModel.CustomPalette = ChartColors
Me.cht.DataSource = sqlds Me.cht.DataBind()
Thanks, Richard
I didn't quite understand the Row/Column usage in the event and eventually found my answer on these forums. I was trying to link the row value to an index in the underyling data source which was the source of my confusion.
I ended up getting around this by building the GanttDataSource by adding in the Series, Items, and TimeEntry objects based on my business objects. This allowed me to set the color of the TimeEntry objects individually based on business logic.
For gantt charts, the row represents the series, while the column represents the task. If you only have one series, then you will always have a row of 0. I do, however, get row numbers other than 0, when I have multiple series in my data. What does your data look like?
I'm currently using an evaluation version to determine if it meets a customer's needs and I'm trying to color boxes individually in the FillSceneGraph event based on some data in the data source.
I took the above code and edited slightly to try and get at the underlying Row to check a value.
My code looks like so:
if (ganttItem != null && ganttItem.Layer != null) { int rowIndex = ganttItem.Row; DataRow r = data.Rows[rowIndex]; if ((int)r["ID"] == 1) { ganttItem.PE.Fill = System.Drawing.Color.Red; } }
However, the gantItem.Row is always 0 and thus I always go to the same row to check the ID.
Am I missing something obvious? Should I be able to get at the row item at that point in the workflow?
Thanks,
John
You can use FillSceneGraph to replace the legend with custom items.
List<Primitive> legendItems = new List<Primitive>();Box legendBox = null;
//find the legend boundsforeach (Primitive p in e.SceneGraph){ if (legendBox == null && p is Box && p.Path != null && p.Path.ToLower().IndexOf("legend") != -1) { legendBox = p as Box; }
if (p.Path != null && p.Path.ToLower().IndexOf("legend") != -1) { legendItems.Add(p); }}
//clean up existing legend itemsforeach (Primitive p in legendItems){ e.SceneGraph.Remove(p);}
//add custom itemsif (legendBox != null){ Box legendItem = new Box(new Rectangle(legendBox.rect.X + 5, legendBox.rect.Y + 5, 20, 20)); legendItem.PE.Fill = Color.Blue; e.SceneGraph.Add(legendItem);
Text legendItemText = new Text(new Point(legendItem.rect.Right + 5, legendBox.rect.Y + legendItem.rect.Height/2 + 5), "legendItemText"); e.SceneGraph.Add(legendItemText);}
Thanks Max for the code. It is very helpful. i need to try the code myself. I have one more query.
Can i control the legend items. i dont want the legend to get generated from the data iam binding.
i want to create some custom legend items of my own.
It would be vewry helpful if you can send some code samaples for the same.
Regards
shiju