Page 1 of 1

Get Info from Gantt serie to display with ToolCursor

Posted: Thu Mar 26, 2015 2:38 pm
by 16069292
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

Re: Get Info from Gantt serie to display with ToolCursor

Posted: Thu Mar 26, 2015 5:31 pm
by Christopher
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;
        }
      }
    }