Page 1 of 1

Gantt chart problems

Posted: Thu Nov 04, 2010 9:10 am
by 9644027
I have a following problem(s). On a gantt chart I want to show duration of all selected projects in the
database. On the bottom axis years are shown and on the left axis project names.
Begin of each gantt chart bar is in the year when project was started and end in the year of
project finalization. However on my gantt chart the first label on bottom axis is always missing.
And I don't now how to set a bottom axis so that all relevant starting and ending years are shown.
In addition on my chart the bars are always to close to the left axis as in the attached image.
Also when I have only two bars, as in the example I have sent to you, bars are to far from each other.
My code is the following and the result I get is in the attachment. As you can see it doesn't look very
representativ and we can't show such chart to our customer.

Code: Select all

         private Steema.TeeChart.TChart chart;
 
        private Steema.TeeChart.Styles.Gantt ganttSeries1;
        private Steema.TeeChart.Tools.GridBand gridBand1;
        String[] heatNumber;
       
        public Gantt_Chart2()
        {
            InitializeComponent();
            InitializeChart1();
        }

        private void InitializeChart1()
        {
            chart = FindName("tChart") as Steema.TeeChart.TChart;
            this.chart.Series.Clear();

            String[] names = { "BHUSHAN CON", "BHUSHAN LF" };
            DateTime[] start = new DateTime[2];
            DateTime[] end = new DateTime[2];

            start[0] = new DateTime(2005, 4, 14, 0, 0, 0);
            end[0] = new DateTime(2009, 4, 14, 0, 0, 0);
         
            start[1] = new DateTime(2005, 4, 14, 0, 0, 0);
            end[1] = new DateTime(2009, 4, 14, 0, 0, 0);

            heatNumber = new String[2];
            heatNumber[0] = "45 387";
            heatNumber[1] = "568";

            if (ganttSeries1 == null)
                ganttSeries1 = new Steema.TeeChart.Styles.Gantt();

            ganttSeries1.Clear();
            this.tChart.Series.Add(ganttSeries1);

            for (int i = 0; i < start.Length; i++)
            {
                //System.Windows.Forms.MessageBox.Show(start[i].ToString() + " " + end[i].ToString());
                ganttSeries1.Add(start[i], end[i], i, names[i].ToString());

            }
            this.gridBand1 = new Steema.TeeChart.Tools.GridBand();

            for (int i = 0; i < ganttSeries1.Count; i++)
            {
                tChart.Axes.Left.Labels.Items.Add(ganttSeries1.YValues[i], ganttSeries1.Labels[i]);
            }

            // tChart1
            // 
            // 
            // tChart1.Aspect
            // 
            this.tChart.Aspect.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            this.tChart.Aspect.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            this.tChart.Aspect.View3D = false;


            this.tChart.Axes.Bottom.Labels.Style = AxisLabelStyle.Value;
            // 
            // tChart1.Header
            // 
            tChart.Header.Visible = true;
            this.tChart.Header.Font.Brush.Color = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            this.tChart.Header.Font.Size = 11;
            this.tChart.Header.Font.SizeFloat = 11F;
            this.tChart.Header.Font.Bold = true;
            this.tChart.Header.Text = "Available number of heats";

            // 
            // tChart1.Panel
            // 
            // 
            // tChart1.Panel.Brush
            // 
            this.tChart.Panel.Brush.Color = System.Drawing.Color.FromArgb(((System.Byte)(254)), ((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255)));
            this.tChart.Panel.Bevel.Inner = BevelStyles.None;
            this.tChart.Panel.Bevel.Outer = BevelStyles.None;
            this.tChart.Series.Add(ganttSeries1);

            this.tChart.Tools.Add(gridBand1);

            tChart.Walls.Visible = false;

            // 
            // tChart1.Walls
            // 
            // 
            // tChart1.Walls.Back
            // 
            // 
            // tChart1.Walls.Back.Brush
            // 
            this.tChart.Walls.Back.Brush.Color = System.Drawing.Color.FromArgb(((System.Byte)(254)), ((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255)));
            this.tChart.Walls.Back.Transparent = false;
            // 
            // tChart1.Walls.Bottom
            // 
            // 
            // tChart1.Walls.Bottom.Pen
            // 
            this.tChart.Walls.Bottom.Pen.Visible = false;
            this.tChart.Walls.Bottom.Size = 3;
            // 
            // tChart1.Walls.Left
            // 
            // 
            // tChart1.Walls.Left.Pen
            // 
            this.tChart.Walls.Left.Pen.Visible = false;
            this.tChart.Walls.Left.Size = 3;
            // 

            // ganttSeries1
            // 
            ganttSeries1.ColorEach = true;
            // 
            // ganttSeries1.EndValues
            // 
            ganttSeries1.EndValues.DataMember = "End";
            ganttSeries1.EndValues.DateTime = true;
            ganttSeries1.LabelMember = "Labels";
            // 
            // ganttSeries1.LinePen
            // 
            ganttSeries1.LinePen.Color = System.Drawing.Color.FromArgb(((System.Byte)(254)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            // 
            // ganttSeries1.Marks
            // 
            // 
            // ganttSeries1.Marks.Symbol
            // 
            // 
            // ganttSeries1.Marks.Symbol.Shadow
            // 
            ganttSeries1.Marks.Symbol.Shadow.Height = 1;
            ganttSeries1.Marks.Symbol.Shadow.Visible = true;
            ganttSeries1.Marks.Symbol.Shadow.Width = 1;
            // 
            // ganttSeries1.NextTasks
            // 
            ganttSeries1.NextTasks.DataMember = "NextTask";
            // 
            // ganttSeries1.Pointer
            // 
            // 
            // ganttSeries1.Pointer.Brush
            // 
            ganttSeries1.ColorEach = true;
            //ganttSeries1.Pointer.Brush.Color = System.Drawing.Color.Red;
            ganttSeries1.Pointer.Brush.ForegroundColor = System.Drawing.Color.Empty;
            ganttSeries1.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Rectangle;
            // 
            // ganttSeries1.StartValues
            // 
            ganttSeries1.StartValues.DataMember = "Start";
            ganttSeries1.StartValues.DateTime = true;
            ganttSeries1.Title = "gantt1";

            ganttSeries1.EndValues.DataMember = "End";
            ganttSeries1.EndValues.DateTime = true;
            // 
            // ganttSeries1.YValues
            // 
            ganttSeries1.YValues.DataMember = "Y";
            ganttSeries1.ShowInLegend = false;
            ganttSeries1.ConnectingPen.Visible = false;
            // 
            // gridBand1
            // 
            this.gridBand1.Axis = this.tChart.Axes.Left;
            // 
            // gridBand1.Band1
            // 
            this.gridBand1.Band1.Color = System.Drawing.Color.FromArgb(((System.Byte)(76)), ((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(192)));
            // 
            // gridBand1.Band2
            // 
            this.gridBand1.Band2.Color = System.Drawing.Color.FromArgb(((System.Byte)(76)), ((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255)));
            // 

            tChart.Axes.Left.MinimumOffset = 10;
            tChart.Axes.Left.MaximumOffset = 10;

            tChart.Axes.Left.AxisPen.Visible = false;
            tChart.Axes.Left.Grid.Visible = false;
            tChart.Axes.Bottom.Grid.Visible = false;

            this.tChart.Axes.Left.Ticks.Visible = false;

            tChart.Axes.Bottom.MinorTicks.Visible = false;
            tChart.Axes.Left.MinorTicks.Visible = false;

            tChart.Axes.Left.Labels.Transparent = true;
            tChart.Panel.Bevel.Outer = BevelStyles.None;
            tChart.Panel.Bevel.Inner = BevelStyles.None;

            ganttSeries1.Marks.Transparent = true;
            ganttSeries1.Marks.Visible = true;
            ganttSeries1.Marks.ArrowLength = -25;

            ganttSeries1.Pointer.VertSize = 10;
            ganttSeries1.Pointer.Pen.Visible = false;

            for (int i = 0; i < ganttSeries1.Count; i++)
            {
                ganttSeries1.GetSeriesMark += new Series.GetSeriesMarkEventHandler(ganttSeries1_GetSeriesMark);
            }

            DateTime sss = DateTime.FromOADate(ganttSeries1.StartValues.Minimum);
            sss.AddYears(-2);
            DateTime eee = DateTime.FromOADate(ganttSeries1.EndValues.Maximum);
            eee = eee.AddYears(1);
            // Set horizontal bottom axis minimum and maximum
            this.tChart.Axes.Bottom.SetMinMax(sss, eee);

            this.tChart.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneYear);
            this.tChart.Axes.Bottom.Labels.DateTimeFormat = "yyyy";

            foreach (AxisLabelItem item in this.tChart.Axes.Left.Labels.Items)
            {
                item.Font.Bold = true;
                item.Font.Brush.Color = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                item.Font.Size = 11;
                item.Font.SizeFloat = 11F;

            }
            Annotation annot1 = new Annotation(tChart.Chart);
            annot1.Text = DateTime.FromOADate(ganttSeries1.StartValues.Minimum).ToString("yyyy");
            annot1.Active = true;
            annot1.Position = AnnotationPositions.LeftBottom;
            annot1.Left = 110;
            annot1.Top = 370;           
        }
        void ganttSeries1_GetSeriesMark(Series series, GetSeriesMarkEventArgs e)
        {
                       e.MarkText = heatNumber[e.ValueIndex];
        }

Thank you in advance.

Re: Gantt chart problems

Posted: Thu Nov 04, 2010 12:17 pm
by narcis
Hi Brinet,

First of all I simplified your code a little bit so that unnecessary code didn't distract me :P.
However on my gantt chart the first label on bottom axis is always missing.
And I don't now how to set a bottom axis so that all relevant starting and ending years are shown.
I found much easier removing custom labels and doing this:

Code: Select all

      this.tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneYear);
      this.tChart1.Axes.Bottom.Labels.DateTimeFormat = "yyyy";

      int minYear = DateTime.FromOADate(ganttSeries1.StartValues.Minimum).Year;
      int maxYear = DateTime.FromOADate(ganttSeries1.EndValues.Maximum).Year;
      DateTime startDate = DateTime.Parse("01/01/" + minYear.ToString());
      DateTime endDate = DateTime.Parse("01/01/" + (maxYear + 1).ToString());

      tChart1.Axes.Bottom.SetMinMax(startDate, endDate);
Complete example is:

Code: Select all

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

    String[] heatNumber;

    private void InitializeChart()
    {

      this.tChart1.Aspect.View3D = false;
      tChart1.Walls.Visible = false;
      tChart1.Legend.Visible = false;
      this.tChart1.Header.Text = "Available number of heats";

      //this.tChart1.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Value;

      tChart1.Axes.Left.MinimumOffset = 10;
      tChart1.Axes.Left.MaximumOffset = 10;

      tChart1.Axes.Left.AxisPen.Visible = false;
      tChart1.Axes.Left.Grid.Visible = false;
      this.tChart1.Axes.Left.Ticks.Visible = false;

      tChart1.Axes.Bottom.MinorTicks.Visible = false;
      tChart1.Axes.Left.MinorTicks.Visible = false;
      tChart1.Axes.Bottom.Grid.Visible = false;

      String[] names = { "BHUSHAN CON", "BHUSHAN LF" };
      DateTime[] start = new DateTime[2];
      DateTime[] end = new DateTime[2];

      start[0] = new DateTime(2005, 4, 14, 0, 0, 0);
      end[0] = new DateTime(2009, 4, 14, 0, 0, 0);

      start[1] = new DateTime(2005, 4, 14, 0, 0, 0);
      end[1] = new DateTime(2009, 4, 14, 0, 0, 0);

      heatNumber = new String[2];
      heatNumber[0] = "45 387";
      heatNumber[1] = "568";

      Steema.TeeChart.Styles.Gantt ganttSeries1 = new Steema.TeeChart.Styles.Gantt(tChart1.Chart);

      ganttSeries1.Marks.Transparent = true;
      ganttSeries1.Marks.Visible = true;
      ganttSeries1.Marks.ArrowLength = -25;

      ganttSeries1.Pointer.VertSize = 10;
      ganttSeries1.Pointer.Pen.Visible = false;

      for (int i = 0; i < start.Length; i++)
      {
        ganttSeries1.Add(start[i], end[i], i, names[i].ToString());
      }

      this.tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneYear);
      this.tChart1.Axes.Bottom.Labels.DateTimeFormat = "yyyy";

      int minYear = DateTime.FromOADate(ganttSeries1.StartValues.Minimum).Year;
      int maxYear = DateTime.FromOADate(ganttSeries1.EndValues.Maximum).Year;
      DateTime startDate = DateTime.Parse("01/01/" + minYear.ToString());
      DateTime endDate = DateTime.Parse("01/01/" + (maxYear + 1).ToString());

      tChart1.Axes.Bottom.SetMinMax(startDate, endDate);
    }
In addition on my chart the bars are always to close to the left axis as in the attached image.
Getting "2005" label visible already solves that, doesn't it?
Also when I have only two bars, as in the example I have sent to you, bars are to far from each other.
You have several options here:

1. Make gantt bars wider:

Code: Select all

      ganttSeries1.Pointer.VertSize = 30;
2. Set left axis minimum and maximum values:

Code: Select all

      tChart1.Axes.Left.SetMinMax(ganttSeries1.MinYValue() - 2, ganttSeries1.MaxYValue() + 2);
3. Increase left axis minimum and maximum offset:

Code: Select all

      tChart1.Axes.Left.MinimumOffset = 50;
      tChart1.Axes.Left.MaximumOffset = 50;
Hope this helps!

Re: Gantt chart problems

Posted: Thu Nov 04, 2010 1:17 pm
by 9644027
Thank a lot!!!! :D It works perfectly now.

Regards