Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
25
Display Custom Time Intervals Along X-AXIS According to Tasks
posted

Hi to all, I want to display custom time intervals along X axis according to tasks in gantt chart. I know giving range for whole X axis. Here is only sample about this.

testChart.Axis.X.RangeType = AxisRangeType.Custom;

testChart.Axis.X.TickmarkStyle = AxisTickStyle.DataInterval;

testChart.Axis.X.TickmarkIntervalType = AxisIntervalType.Months;

testChart.Axis.X.TickmarkInterval = 1;

testChart.Axis.X.RangeMin =
DateTime.Now.Ticks;

testChart.Axis.X.RangeMax = DateTime.Now.AddDays(180).Ticks;

BUT , I don't want to do this. I want to show time interval for each task. I'm sending what i want to do.

The main question is showing the START - END date per task. (for every task) START- END date have not definite format such as week, month, quarter or year. Every task has custom START - END dates.  

Thanks for your help.

  • 26458
    Offline posted

    While there's no out-of-the-box way to accomplish this, you can use FillSceneGraph event to draw custom labels and lines on the chart. Here's a quick sample:

    private void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e)
    {
       IAdvanceAxis yAxis = (IAdvanceAxis)e.Grid["Y"];
       PrimitiveCollection labels = new PrimitiveCollection();
      
       foreach
    (Primitive p in e.SceneGraph)
       {
          Box b = p as Box;
          if (b != null && b.Layer != null)
          {
             DateTime[ dates = b.Value as DateTime[;
             if (dates != null)
             {
                Line startLine = new Line(new Point(b.rect.X, b.rect.Bottom), new Point(b.rect.X, (int)yAxis.MapMinimum), new LineStyle(LineCapStyle.NoAnchor, LineCapStyle.NoAnchor, LineDrawStyle.Dash));
                startLine.PE.Stroke =
    Color.Magenta;
                labels.Add(startLine);
                LabelStyle labelStyle = new LabelStyle();
                labelStyle.Orientation =
    TextOrientation.VerticalLeftFacing;
                Text startLabel = new Text();
                startLabel.SetTextString(dates[0].ToShortDateString());
                startLabel.SetLabelStyle(labelStyle);
                SizeF labelSize = Platform.GetStringSizePixels(startLabel.GetTextString(), labelStyle.Font);
                startLabel.bounds =
    new Rectangle(b.rect.X, (int)yAxis.MapMinimum, (int)labelSize.Height, (int)labelSize.Width);
                labels.Add(startLabel);

                Line endLine = new Line(new Point(b.rect.Right, b.rect.Bottom), new Point(b.rect.Right, (int)yAxis.MapMinimum), new LineStyle(LineCapStyle.NoAnchor, LineCapStyle.NoAnchor, LineDrawStyle.Dash));
                endLine.PE.Stroke =
    Color.Magenta;
                labels.Add(endLine);
                Text endLabel = new Text();
                endLabel.SetTextString(dates[1].ToShortDateString());
                endLabel.SetLabelStyle(labelStyle);
                labelSize =
    Platform.GetStringSizePixels(endLabel.GetTextString(), labelStyle.Font);
                endLabel.bounds =
    new Rectangle(b.rect.Right, (int)yAxis.MapMinimum, (int)labelSize.Height, (int)labelSize.Width);
                labels.Add(endLabel);
             }
          }
       }

       foreach (Primitive p in labels)
       {
          e.SceneGraph.Add(p);
       }
    }