Page 1 of 1

Binding Gantt

Posted: Mon Sep 05, 2016 12:08 pm
by 16078518
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

Re: Binding Gantt

Posted: Tue Sep 06, 2016 11:03 am
by Christopher
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;
    }

Re: Binding Gantt

Posted: Tue Sep 06, 2016 12:57 pm
by 16078518
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 14545 times
Is it possible also to insert mark inside, different of label ?

Thank you

Regards,

Philippe

Re: Binding Gantt

Posted: Tue Sep 06, 2016 4:46 pm
by Christopher
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 14510 times

Re: Binding Gantt

Posted: Wed Sep 07, 2016 7:43 am
by 16078518
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 14504 times
Thank you

Regards

Philippe

Re: Binding Gantt

Posted: Wed Sep 07, 2016 9:23 am
by Christopher
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 14500 times

Re: Binding Gantt

Posted: Wed Sep 07, 2016 1:16 pm
by 16078518
Christopher,

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

Thank you

Philippe

Re: Binding Gantt

Posted: Wed Sep 07, 2016 3:06 pm
by Christopher
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 14493 times