Gantt chart: add a label on a connecting pen

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
gcoray
Newbie
Newbie
Posts: 2
Joined: Mon Oct 04, 2010 12:00 am

Gantt chart: add a label on a connecting pen

Post by gcoray » Tue Oct 25, 2011 10:21 am

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 3714 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.

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

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

Post by Yeray » Tue Oct 25, 2011 2:38 pm

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

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

Post by Narcís » Tue Oct 25, 2011 2:54 pm

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;
        }
      }
    }
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

gcoray
Newbie
Newbie
Posts: 2
Joined: Mon Oct 04, 2010 12:00 am

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

Post by gcoray » Tue Oct 25, 2011 3:43 pm

Hi,

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

Best regards.

Post Reply