Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
100
Composite Gantt Chart
posted

Hi,

I've had a Gantt chart working fine for a while binding to a datatable with columns (GanttSeries, GanttTask, GanttStart, GanttEnd). Im now trying to turn this into a composite chart to layer two gantt charts on top of each other. I have a composite chart working with linechart (based on the doc example) so I copied this and adapted for the Gantt but its not working.

I've constructed the Gantt series manually so I can work with my existing DAL and the above data table. 

Can anyone see what im doing wrong?

private Dictionary<string,GanttSeries> CreateGanttSeries(DataTable table, bool background)

{

Dictionary<string,GanttSeries> results = new Dictionary<string,GanttSeries>();foreach (DataRow row in table.Rows)

{

GanttSeries value;

if( !results.TryGetValue(row["GanttSeries"].ToString(), out value) ) {results.Add(row["GanttSeries"].ToString(), new GanttSeries(row["GanttSeries"].ToString()));

}

GanttItem item = new GanttItem();

item.Key = row["GanttTask"].ToString();

DateTime starttime = (DateTime)row["GanttStart"];

DateTime endtime = (DateTime)row["GanttEnd"];

item.Times.Add(new GanttTimeEntry(starttime,endtime));

results[row["GanttSeries"].ToString()].Items.Add(item);

}

return results;

}

private void FormatGanttChart(DateTime starttime, DateTime endtime)

{

this.ganttchart1.CompositeChart.ChartLayers.Clear();

this.myChartArea.Axes.Clear();

//Create New Axis

globalAxisX = new AxisItem();

globalAxisX.OrientationType = AxisNumber.X_Axis;

globalAxisX.DataType = AxisDataType.Time;

globalAxisX.SetLabelAxisType = SetLabelAxisType.ContinuousData;

globalAxisX.Labels.Orientation = TextOrientation.VerticalLeftFacing;

globalAxisX.LineThickness = 1;

globalAxisX.RangeType =
AxisRangeType.Custom;

globalAxisX.RangeMin = starttime.Ticks;

globalAxisX.RangeMax = endtime.Ticks;

globalAxisY =
new AxisItem();

globalAxisY.OrientationType = AxisNumber.Y_Axis;

globalAxisY.RangeType = AxisRangeType.Automatic;globalAxisY.DataType = AxisDataType.String;

globalAxisY.LineThickness = 1;

myChartArea.Axes.Add(globalAxisX);

myChartArea.Axes.Add(globalAxisY);

ChartLayerAppearance layer = new ChartLayerAppearance();

layer.ChartArea = myChartArea;

layer.AxisX = globalAxisX;

layer.AxisY = globalAxisY;

Dictionary<string, GanttSeries> mainseries = CreateGanttSeries(this.ds_GanttChart, false);foreach (KeyValuePair<string, GanttSeries> serieskvp in mainseries)

{

layer.Series.Add(serieskvp.Value);

}

this.ganttchart1.CompositeChart.ChartLayers.Add(layer);

}

Thanks,

Parents
  • 26458
    Offline posted

    You just need to specify the chart type of your layer and add it to the layers collection of the composite chart. Also, each series needs to be added to both layer.Series and chart.CompositeChart.Series.

    Here's an example:

    DataTable dt = new DataTable();
    dt.Columns.Add(
    "Start", typeof(DateTime));
    dt.Columns.Add(
    "End", typeof(DateTime));
    dt.Columns.Add(
    "Task", typeof(string));
    dt.Columns.Add(
    "LinkTo", typeof(int));
    dt.Columns.Add(
    "Owner", typeof(int));
    dt.Columns.Add(
    "PercentComplete", typeof(double));
    dt.Columns.Add(
    "ID", typeof(string));

    dt.Rows.Add(new object[ { DateTime.Now, DateTime.Now.AddDays(1), "task1", 0, 0, 100, "id1" });
    dt.Rows.Add(
    new object[ { DateTime.Now.AddDays(3), DateTime.Now.AddDays(5), "task2", 0, 0, 100, "id1" });

    ChartArea area = new ChartArea();
    ultraChart1.CompositeChart.ChartAreas.Add(area);

    AxisItem x = new AxisItem(ultraChart1, AxisNumber.X_Axis);
    x.DataType =
    AxisDataType.Time;
    area.Axes.Add(x);

    AxisItem y = new AxisItem(ultraChart1, AxisNumber.Y_Axis);
    y.DataType =
    AxisDataType.String;
    area.Axes.Add(y);

    GanttSeries s = new GanttSeries();
    s.Data.DataSource = dt;
    s.Data.StartTimeColumn =
    "Start";
    s.Data.EndTimeColumn =
    "End";
    s.Data.LabelColumn =
    "Task";
    s.Data.LinkToIDColumn =
    "LinkTo";
    s.Data.OwnerColumn =
    "Owner";
    s.Data.PercentCompleteColumn =
    "PercentComplete";
    s.Data.TimeEntryIDColumn =
    "ID";
    s.DataBind();

    ChartLayerAppearance layer = new ChartLayerAppearance();
    ultraChart1.CompositeChart.ChartLayers.Add(layer);
    layer.ChartType =
    ChartType.GanttChart;
    layer.ChartArea = area;
    layer.AxisX = x;
    layer.AxisY = y;
    layer.Series.Add(s);

    ultraChart1.CompositeChart.Series.Add(s);

Reply Children
No Data