Get Info from Gantt serie to display with ToolCursor

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Philippe
Newbie
Newbie
Posts: 1
Joined: Wed May 21, 2014 12:00 am

Get Info from Gantt serie to display with ToolCursor

Post by Philippe » Thu Mar 26, 2015 2:38 pm

Dear Sir,

I'm using Tchart 2015 WPF, how can get the task name from a Gantt Serie when the CurorTool is moving on the task.

The gantt series are created in this way.

Gantt gantt = new Gantt();
gantt.Marks.Visible = true;
gantt.Add(DateTime.Now.AddDays(-4), DateTime.Now.AddDays(-2), 2, "P1");
gantt.Add(DateTime.Now.AddDays(0), DateTime.Now.AddDays(1), 2, "P2");

Gantt gantt1 = new Gantt();
gantt1.Marks.Visible = true;
gantt1.Add(DateTime.Now.AddDays(-6), DateTime.Now.AddDays(-4), 5, "P3");
gantt1.Add(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(0), 5, "P4");

tChart.Axes.Left.Labels.Style = AxisLabelStyle.Value;
//tChart.Series.Add(serie1);
//tChart.Series.Add(serie2);
tChart.Series.Add(gantt);
tChart.Series.Add(gantt1);

In the CursorChange Event I get the current date of the cursor with :

_currentCursorPositionDate = DateTime.FromOADate(tChart.Series[0].XScreenToValue(e.x));

How Get the Task Name of the series at this datetime ?

Thank you

Regards,

Philippe

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

Re: Get Info from Gantt serie to display with ToolCursor

Post by Christopher » Thu Mar 26, 2015 5:31 pm

Hello,

You can try something like this:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Legend.Visible = false;

      Gantt gantt = new Gantt();
      gantt.Marks.Visible = true;
      gantt.Add(DateTime.Now.AddDays(-4), DateTime.Now.AddDays(-2), 2, "P1");
      gantt.Add(DateTime.Now.AddDays(0), DateTime.Now.AddDays(1), 2, "P2");

      Gantt gantt1 = new Gantt();
      gantt1.Marks.Visible = true;
      gantt1.Add(DateTime.Now.AddDays(-6), DateTime.Now.AddDays(-4), 5, "P3");
      gantt1.Add(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(0), 5, "P4");

      tChart1.Axes.Left.Labels.Style = AxisLabelStyle.Value;
      //tChart.Series.Add(serie1);
      //tChart.Series.Add(serie2);
      tChart1.Series.Add(gantt);
      tChart1.Series.Add(gantt1);

      CursorTool tool = new CursorTool(tChart1.Chart);
      tool.Style = CursorToolStyles.Vertical;
      tool.Change += tool_Change;
      tool.FollowMouse = true;
    }

    DateTime _currentCursorPositionDate;
    void tool_Change(object sender, CursorChangeEventArgs e)
    {
      _currentCursorPositionDate = DateTime.FromOADate(e.XValue);

      tChart1.Header.Text = _currentCursorPositionDate.ToShortDateString();

      Gantt series = tChart1.Series[0] as Gantt;

      for (int i = 0; i < series.Count; i++)
      {
        double startDate = series.StartValues[i];
        double endDate = series.EndValues[i];

        if (startDate < e.XValue && endDate > e.XValue)
        {
          tChart1.Header.Text = series[i].Label;
        }
      }
    }
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