Page 1 of 1

Gantt chart: add a label on a connecting pen

Posted: Tue Oct 25, 2011 10:21 am
by 8752374
Hello,

I have a Gantt serie with some bars. I want to display a line between each bar which will have a label associated.

Example with the picture below:
ganttexample.png
Label on lines example
ganttexample.png (4.21 KiB) Viewed 3711 times
The two blocks REQA and ATQA are connected (using the NextTasks property) and a line is displayed between them (using the ConnectingPen property).
Is there a way to add a label on this line, like for the blocks ?

Best regards.

Re: Gantt chart: add a label on a connecting pen

Posted: Tue Oct 25, 2011 2:38 pm
by yeray
Hello,

I'm afraid this is not possible right now. However, it wouldn't be very difficult, for example, to have an array of Annotation tools to show the desired texts.

Re: Gantt chart: add a label on a connecting pen

Posted: Tue Oct 25, 2011 2:54 pm
by narcis
Hi gcoray,

Yes, you can do that using Annotation tools set to a custom position in the OnAfterDraw event as in the example here:

Code: Select all

    public Form1()
    {
      InitializeComponent();
      InitializeChart();
    }

    private Steema.TeeChart.Styles.Gantt gantt1;

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Legend.Visible = false;

      gantt1 = new Steema.TeeChart.Styles.Gantt(tChart1.Chart);
      gantt1.Add(DateTime.Now, DateTime.Now.AddDays(2), 1, "task1");
      gantt1.NextTasks[0]=gantt1.Add(DateTime.Now.AddDays(4), DateTime.Now.AddDays(5), 1, "task2");

      tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);

      tChart1.Draw();
    }

    void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
    {
      for (int i = 0; i < gantt1.NextTasks.Count; i++)
      {
        int next = (int)gantt1.NextTasks[i];
        if (next != -1)
        {
          Steema.TeeChart.Tools.Annotation annotation1 = new Steema.TeeChart.Tools.Annotation(tChart1.Chart);
          annotation1.Shape.CustomPosition = true;
          annotation1.Text = "Connecting line " + i.ToString();

          SizeF textSize = g.MeasureString(annotation1.Shape.Font, annotation1.Text);
                    
          int x = gantt1.CalcXPosValue(gantt1.EndValues[i]) + (gantt1.CalcXPosValue(gantt1.StartValues[next]) - gantt1.CalcXPosValue(gantt1.EndValues[i])) / 2;
          int y = gantt1.CalcYPos(i) - 30;

          annotation1.Shape.Left = x - (int)textSize.Width / 2;
          annotation1.Shape.Top = y;
        }
      }
    }

Re: Gantt chart: add a label on a connecting pen

Posted: Tue Oct 25, 2011 3:43 pm
by 8752374
Hi,

Thank you very much ! I think this will be fine.

Best regards.