Binding Gantt

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Philippe
Newbie
Newbie
Posts: 6
Joined: Fri Jun 17, 2016 12:00 am

Binding Gantt

Post by Philippe » Mon Sep 05, 2016 12:08 pm

Dear Sir,
I want to bind data to a chart gantt in order to have :
- Start Date
- End Date
- Y value
- Color
- Label

I tried this solution without success :

Code: Select all

 public class GanttData
    {
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public int Y { get; set; }
        public string Label { get; set; }
        public Color Color { get; set; }
    }

          public MainWindow()
        {
            InitializeComponent();

            List<GanttData> lstData = new List<GanttData>();

            GanttData data1;
            
            data1 = new GanttData();
            data1.Color = Colors.Red;
            data1.Start = DateTime.Today;
            data1.End = data1.Start.AddDays(3);
            data1.Label = "Un";
            data1.Y = 1;
            lstData.Add(data1);

            data1 = new GanttData();
            data1.Color = Colors.Green;
            data1.Start = DateTime.Today.AddDays(1);
            data1.End = data1.Start.AddDays(1);
            data1.Label = "Deux";
            data1.Y = 2;
            lstData.Add(data1);

            tChart.Aspect.View3D = false;
            tChart.Header.Text = "Gantt MultipleNextTasks";
            tChart.Legend.Visible = false;

            Gantt gantt = new Gantt(tChart.Chart);
            gantt.ConnectingPen.Visible = false;
            gantt.LabelMember = "Label";

            gantt.Add(lstData);
          }
What is wrong ?
Could you please help me ?

Thank you

Regards,

Philippe

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Binding Gantt

Post by Christopher » Tue Sep 06, 2016 11:03 am

Hello Philippe,
Philippe wrote: What is wrong ?
Could you please help me ?
Of course. Your class should look like this:

Code: Select all

  public class GanttData
  {
    public double Start { get; set; }
    public double End { get; set; }
    public int Y { get; set; }
    public string Label { get; set; }
    public Color Color { get; set; }
  }
which you can consume like this:

Code: Select all

    private void InitializeChart()
    {
      List<GanttData> lstData = new List<GanttData>();

      GanttData data1;

      data1 = new GanttData();
      data1.Color = Color.Red;
      data1.Start = DateTime.Today.ToOADate();
      data1.End = DateTime.FromOADate(data1.Start).AddDays(3).ToOADate();
      data1.Label = "Un";
      data1.Y = 1;
      lstData.Add(data1);

      data1 = new GanttData();
      data1.Color = Color.Green;
      data1.Start = DateTime.Today.AddDays(1).ToOADate();
      data1.End = DateTime.FromOADate(data1.Start).AddDays(1).ToOADate();
      data1.Label = "Deux";
      data1.Y = 2;
      lstData.Add(data1);

      tChart1.Aspect.View3D = false;
      tChart1.Header.Text = "Gantt MultipleNextTasks";
      tChart1.Legend.Visible = false;

      Gantt gantt = new Gantt(tChart1.Chart);
      gantt.ConnectingPen.Visible = false;
      gantt.LabelMember = "Label";
      gantt.ColorMember = "Color";
      gantt.StartValues.DataMember = "Start";
      gantt.EndValues.DataMember = "End";
      gantt.YValues.DataMember = "Y";

      gantt.DataSource = lstData;
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Philippe
Newbie
Newbie
Posts: 6
Joined: Fri Jun 17, 2016 12:00 am

Re: Binding Gantt

Post by Philippe » Tue Sep 06, 2016 12:57 pm

Dear Christopher,

Thank you very much for your reply.
I applied your code but the result is wrong about the date displayed.
Gantt.png
Gantt.png (7.27 KiB) Viewed 14537 times
Is it possible also to insert mark inside, different of label ?

Thank you

Regards,

Philippe

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Binding Gantt

Post by Christopher » Tue Sep 06, 2016 4:46 pm

Hello Phillippe,

Many apologies for not seeing that issue earlier - I have added it to our ticket tracker with id=1621 and have already resolved it, meaning that a resolution to this problem will be found in the next maintenance release, due out in the middle of this month. I'm afraid to say that there is no workaround available to this issue.
636087840928155850.jpg
636087840928155850.jpg (26.46 KiB) Viewed 14502 times
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Philippe
Newbie
Newbie
Posts: 6
Joined: Fri Jun 17, 2016 12:00 am

Re: Binding Gantt

Post by Philippe » Wed Sep 07, 2016 7:43 am

Dear Christopher,

No problem, until the release I resolved in this way :

Code: Select all

           foreach (GanttData data in lstData)
            {
                gantt.Add(data.Start, data.End, data.Y, data.Label, data.Color);
            }
Is it possible to have the Marks with different value ?
How to do it ?
gantt.png
gantt.png (11.05 KiB) Viewed 14496 times
Thank you

Regards

Philippe

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Binding Gantt

Post by Christopher » Wed Sep 07, 2016 9:23 am

Hello Phillippe,

You always have the option to do something like this:

Code: Select all

    private void InitializeChart()
    {
      List<GanttData> lstData = new List<GanttData>();

      GanttData data1;
      DateTime date = DateTime.Today;

      for (int i = 0; i < 3; i++)
      {
        data1 = new GanttData();
        data1.Color = Color.Red;
        data1.Start = date;
        date = date.AddDays(3);
        data1.End = date;
        data1.Label = "Un " + ((i > 0) ? i.ToString() : "");
        data1.Y = 1;
        lstData.Add(data1);
      }

      date = DateTime.Today.AddDays(1);

      for (int i = 0; i < 3; i++)
      {
        data1 = new GanttData();
        data1.Color = Color.Green;
        data1.Start = date;
        date = date.AddDays(3);
        data1.End = date;
        data1.Label = "Deux " + ((i > 0) ? i.ToString() : "");
        data1.Y = 2;
        lstData.Add(data1);
      }

      tChart1.Aspect.View3D = false;
      tChart1.Header.Text = "Gantt MultipleNextTasks";
      tChart1.Legend.Visible = false;

      Gantt gantt = new Gantt(tChart1.Chart);
      gantt.ConnectingPen.Visible = false;
      gantt.Marks.Visible = true;

      foreach (GanttData data in lstData)
      {
        gantt.Add(data.Start, data.End, data.Y, data.Label, data.Color);
      }
    }
which will give you the following chart:
636088441629616701.jpg
636088441629616701.jpg (31.52 KiB) Viewed 14492 times
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Philippe
Newbie
Newbie
Posts: 6
Joined: Fri Jun 17, 2016 12:00 am

Re: Binding Gantt

Post by Philippe » Wed Sep 07, 2016 1:16 pm

Christopher,

Yes, but the first 'Mark' value is the same of the Label !
No other possibilities to avoid this ?

Thank you

Philippe

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Binding Gantt

Post by Christopher » Wed Sep 07, 2016 3:06 pm

Hello Phillippe,

Yes, you can use Custom Labels, e.g.

Code: Select all

    private void InitializeChart()
    {
      List<GanttData> lstData = new List<GanttData>();

      GanttData data1;
      DateTime date = DateTime.Today;

      for (int i = 0; i < 3; i++)
      {
        data1 = new GanttData();
        data1.Color = Color.Red;
        data1.Start = date;
        date = date.AddDays(3);
        data1.End = date;
        data1.Label = "Un " + ((i > 0) ? i.ToString() : "");
        data1.Y = 1;
        lstData.Add(data1);
      }

      date = DateTime.Today.AddDays(1);

      for (int i = 0; i < 3; i++)
      {
        data1 = new GanttData();
        data1.Color = Color.Green;
        data1.Start = date;
        date = date.AddDays(3);
        data1.End = date;
        data1.Label = "Deux " + ((i > 0) ? i.ToString() : "");
        data1.Y = 2;
        lstData.Add(data1);
      }

      tChart1.Aspect.View3D = false;
      tChart1.Header.Text = "Gantt MultipleNextTasks";
      tChart1.Legend.Visible = false;

      Gantt gantt = new Gantt(tChart1.Chart);
      gantt.ConnectingPen.Visible = false;
      gantt.Marks.Visible = true;

      foreach (GanttData data in lstData)
      {
        gantt.Add(data.Start, data.End, data.Y, data.Label, data.Color);
      }

      tChart1.Axes.Left.Labels.Items.Add(1, "Uno");
      tChart1.Axes.Left.Labels.Items.Add(2, "Dos");
    }
which gives me:
636088647703420932.jpg
636088647703420932.jpg (31.95 KiB) Viewed 14485 times
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply