Jump to content
Software FX Community

Gantt Chart Problem


Ronak
 Share

Recommended Posts

Hi...

 

I am trying to create a gantt chart. from a DataTable.

 

DataTable property

--------------------

TaskName | StartTime |  EndTime...

 

Where each task has a name and its execution start time and end time. There are more than 20 rows in this table..

 

Sometimes task execution last for only 2 seconds. so, my first question is is there nay way to Step through only seconds on Yaxis. Here is my code...

 

2) Setp in seconds in not possible then Is there any way i can show a perticular sectioin of my graph with certain zoom. So, user can have better look and feel and Use the scroll bar to go the other places in graph...

 

I have code that works but the block i am getting for each start and end.. is very tiny...I have also attached the image of my graph. as you can see that each bar is so small. Can i lock the scoll bar for single day..or something...Here is the data from data grid...

 

Success Failure

02-16-07 09:47:49

02-16-07 09:48:17

  02-16-07 10:16:09

  02-16-07 10:19:06

  02-16-07 11:21:58

02-21-07 04:50:05

02-21-07 09:48:56

 

where duration of each task is either 2 or 3 second..

 

 

 

Code:

chart1.Series.Clear();

 

chart1.Data.Clear();

 

chart1.Gallery = Gallery.Gantt;

 

chart1.AxisY.Title.Text = "Execution Time";

 

chart1.AxisY.Position = AxisPosition.Far;

 

chart1.AxisY.LabelsFormat.Format = AxisFormat.DateTime;

 

chart1.AxisY.LabelsFormat.CustomFormat = "MM-dd-yy hh:mm:ss";

 

//chart1.AxisY.LabelAngle = 45;

 

chart1.AxisY.Staggered = true;

 

chart1.AxisY.AutoScroll = true;

 

chart1.AxisY.Step = 1;

 

chart1.AxisY.Notify = true;

 

chart1.AxisY.PixelsPerUnit = 15;

 

chart1.AxisY.Grids.Major.Visible = true;

 

 

chart1.AxisX.Title.Text = "Task: Test1";

 

//chart1.AxisX.Labels[0] = "Test1";

 

chart1.Data.Series = 2;

 

chart1.Series[0].Text = "Success";

 

chart1.Series[1].Text = "Failure";

 

chart1.AxisX.Inverted = true;

 

chart1.AxisX.AutoScroll = true;

 

chart1.AxisX.PixelsPerUnit = 15;

 

chart1.AxisX.Grids.Major.Visible = true;

 

 

 

String filter = "Name = 'Test1'";

 

//int nSeries = 0;

 

int nPoints = 0;

 

foreach (DataRow datarow in table.Select(filter,"Start"))

 

{

 

 

DateTime start = (DateTime)datarow["Start"];

 

DateTime end = (DateTime)datarow["End"];

 

if ((int)datarow["ResultCode"] == 1)

 

{

 

chart1.Data.YFrom[0, nPoints] = start.ToOADate();

 

chart1.Data.Y[0, nPoints] = end.ToOADate();

 

}

 

if ((int)datarow["ResultCode"] == 2)

 

{

 

chart1.Data.YFrom[1, nPoints] = start.ToOADate();

 

chart1.Data.Y[1, nPoints] = end.ToOADate();

 

}

 

nPoints++;

 

}

Link to comment
Share on other sites

The follwing code creates a chart with an interval of 5 minutes and bars that spawn 3 seconds:

 chart1.AxisY.LabelsFormat.Format = AxisFormat.Time;  chart1.AxisY.Min = new DateTime(2007,1,1,0,0,0).ToOADate();  chart1.AxisY.Max = new DateTime(2007,1,1,0,5,0).ToOADate();

 chart1.Data.Series = 0;  chart1.Data.Points = 3;

 chart1.Data.YFrom[0] = new DateTime(2007,1,1,0,1,0).ToOADate();  chart1.Data.Y[0] = new DateTime(2007,1,1,0,1,3).ToOADate();

 chart1.Data.YFrom[1] = new DateTime(2007,1,1,0,2,0).ToOADate();  chart1.Data.Y[1] = new DateTime(2007,1,1,0,2,3).ToOADate();

 chart1.Data.YFrom[2] = new DateTime(2007,1,1,0,3,0).ToOADate();  chart1.Data.Y[2] = new DateTime(2007,1,1,0,3,3).ToOADate();

Zoom is supported in all axis-based chart types.

Link to comment
Share on other sites

Hi Frank,

 

Thanks for your reply. I treid your solution..but i am still getting the same output. I just want to make the bars look bigger.. If you see my image..There are five bars in very small period and only two bars at the end. I have also put autoscroll for both X and Y axis to true, but still i dont know why it is not coming. The image should have autoscroll when it thinks that it is going out of size for bars. Here is my second example.. Basically i want to have look and feel like this. But the below example has Days as Step not the seconds or minute. And everything is in Days nothing in time. While creating the actual Gantt chart i have to deal with seconds.. as each task may take more than 1 second also. How do the setScroll view in my above example. i tired it but somehow my application crashes.. when i enable zoom or setting the zoom level or doing the setscrollview in my above graph.

 

Temp Example:

 

chart1.Series.Clear();   chart1.Data.Clear();   chart1.Gallery = Gallery.Gantt;     chart1.AxisY.Title.Text = "Dates";   chart1.AxisY.Position = AxisPosition.Far;   chart1.AxisY.LabelsFormat.Format = AxisFormat.Date;   chart1.AxisY.LabelsFormat.CustomFormat = "MM-dd-yyyy";   //chart1.AxisY.LabelAngle = 45;     chart1.AxisY.Staggered = true;   chart1.AxisY.AutoScroll = true;   chart1.AxisY.Step = 5;     chart1.AxisY.Notify = true;   chart1.AxisY.PixelsPerUnit = 15;     chart1.AxisY.Grids.Major.Visible = true;   chart1.AxisX.Title.Text = "Developers";   chart1.AxisX.Labels[0] = "Ronak";   chart1.AxisX.Labels[1] = "Brad";   chart1.AxisX.Labels[2] = "Scott";   chart1.AxisX.Labels[3] = "Natalie";   chart1.AxisX.Inverted = true;   chart1.AxisX.AutoScroll = true;   chart1.AxisX.PixelsPerUnit = 15;   chart1.AxisX.Grids.Major.Visible = true;     DateTime start = DateTime.Now.Date;       chart1.Data.YFrom[0, 0] = start.ToOADate();   chart1.Data.Y[0, 0] = start.AddDays(5).ToOADate();     chart1.Data.YFrom[0, 1] = start.AddDays(8).ToOADate();   chart1.Data.Y[0, 1] = start.AddDays(9).ToOADate();   chart1.Data.YFrom[0, 2] = start.AddDays(11).ToOADate();   chart1.Data.Y[0, 2] = start.AddDays(15).ToOADate();   chart1.Data.YFrom[0, 3] = start.AddDays(18).ToOADate();   chart1.Data.Y[0, 3] = start.AddDays(25).ToOADate();     chart1.Data.YFrom[1, 0] = start.AddDays(7).ToOADate();   chart1.Data.Y[1, 0] = start.AddDays(12).ToOADate();   chart1.Data.YFrom[1, 1] = start.AddDays(10).ToOADate();   chart1.Data.Y[1, 1] = start.AddDays(19).ToOADate();   chart1.Data.YFrom[1, 2] = start.AddDays(12).ToOADate();   chart1.Data.Y[1, 2] = start.AddDays(17).ToOADate();   chart1.Data.YFrom[1, 3] = start.AddDays(26).ToOADate();   chart1.Data.Y[1, 3] = start.AddDays(40).ToOADate();   chart1.Data.YFrom[2, 0] = start.AddDays(7).ToOADate();   chart1.Data.Y[2, 0] = start.AddDays(12).ToOADate();   chart1.Data.YFrom[2, 1] = start.AddDays(10).ToOADate();   chart1.Data.Y[2, 1] = start.AddDays(19).ToOADate();   chart1.Data.YFrom[2, 2] = start.AddDays(12).ToOADate();   chart1.Data.Y[2, 2] = start.AddDays(17).ToOADate();   chart1.Data.YFrom[2, 3] = start.AddDays(26).ToOADate();   chart1.Data.Y[2, 3] = start.AddDays(40).ToOADate();   chart1.Series[0].Text = "Beta1";   chart1.Series[1].Text = "Beta2";   chart1.Series[2].Text = "Beta3"; 

Link to comment
Share on other sites

Hi Frank,

 Using your previous post i tried to create the Gantt chart.. but still the bars are so small and i am not able to get the Scroll bar so.. I can see a perticular section of graph very clearly...

 

Here is my code. In this i changed the Y axis format to Time also.. still no luck.. Just put this one in whole new project...I also have given you sample data from my TaskExecute datatable.. as you can see the starttime and endtime has the duration of beteeen 2-4 seconds...

Is there any way to zoom and set the center to sepefic area of chart. so you can have better look and feel. 

/* TaskName StartTime EndTime ResultCode -----------------------------------------------------------------------     Test1   2/16/2007 9:47:46 PM   2/16/2007 9:47:49 PM   1   Test1   2/16/2007 9:48:15 PM   2/16/2007 9:48:17 PM   1   Test1   2/16/2007 10:16:07 PM   2/16/2007 10:16:09 PM   2   Test1   2/16/2007 10:19:04 PM   2/16/2007 10:19:06 PM   2   Test1   2/16/2007 11:21:56 PM   2/16/2007 11:21:58 PM   2     Test1   2/21/2007 4:50:02 PM   2/21/2007 4:50:05 PM   1   Test1   2/21/2007 9:48:53 PM   2/21/2007 9:48:56 PM   1   Test1   2/23/2007 5:08:21 PM   2/23/2007 5:08:25 PM   1   Test1   2/23/2007 5:08:28 PM   2/23/2007 5:08:30 PM   1   Test1   2/23/2007 5:08:33 PM   2/23/2007 5:08:35 PM   1 -----------------------------------------------------------------------   */   chart1.Series.Clear();   chart1.Data.Clear();   chart1.Gallery = Gallery.Gantt;   chart1.AxisY.Title.Text = "Dates";   chart1.AxisY.Position = AxisPosition.Far;   chart1.AxisY.LabelsFormat.Format = AxisFormat.Time;   chart1.AxisY.LabelsFormat.CustomFormat = "MM-dd-yy hh:mm:ss";     chart1.AxisY.Staggered = true;   chart1.AxisY.AutoScroll = true;   //chart1.AxisY.Step = 5;   chart1.AxisY.Notify = true;   chart1.AxisY.PixelsPerUnit = 15;   chart1.AxisY.Grids.Major.Visible = true;   chart1.AxisX.Title.Text = "Task : Test1";   chart1.AxisX.Inverted = true;   chart1.AxisX.AutoScroll = true;   chart1.AxisX.PixelsPerUnit = 15;   chart1.AxisX.Grids.Major.Visible = true;   chart1.Data.Series = 2;   chart1.Series[0].Text = "Success";   chart1.Series[1].Text = "Failure";   chart1.Data.YFrom[0, 0] = Convert.ToDateTime("2/16/2007 9:47:46 PM").ToOADate();   chart1.Data.Y[0, 0] = Convert.ToDateTime("2/16/2007 9:47:49 PM").ToOADate();   chart1.Data.YFrom[0, 1] = Convert.ToDateTime("2/16/2007 9:48:15 PM").ToOADate();   chart1.Data.Y[0, 1] = Convert.ToDateTime("2/16/2007 9:48:17 PM").ToOADate();   chart1.Data.YFrom[1, 2] = Convert.ToDateTime("2/16/2007 10:16:07 PM").ToOADate();   chart1.Data.Y[1, 2] = Convert.ToDateTime("2/16/2007 10:16:09 PM").ToOADate();   chart1.Data.YFrom[1, 3] = Convert.ToDateTime("2/16/2007 10:19:04 PM").ToOADate();   chart1.Data.Y[1, 3] = Convert.ToDateTime("2/16/2007 10:19:09 PM").ToOADate();   chart1.Data.YFrom[1, 4] = Convert.ToDateTime("2/16/2007 11:21:56 PM").ToOADate();   chart1.Data.Y[1, 4] = Convert.ToDateTime("2/16/2007 11:21:58 PM").ToOADate();   chart1.Data.YFrom[0, 6] = Convert.ToDateTime("2/21/2007 4:50:02 PM").ToOADate();   chart1.Data.Y[0, 6] = Convert.ToDateTime("2/21/2007 4:50:05 PM").ToOADate();   chart1.Data.YFrom[0, 7] = Convert.ToDateTime("2/21/2007 9:48:53 PM").ToOADate();   chart1.Data.Y[0, 7] = Convert.ToDateTime("2/21/2007 9:48:56 PM").ToOADate();     chart1.Data.YFrom[0, 8] = Convert.ToDateTime("2/23/2007 5:08:21 PM").ToOADate();   chart1.Data.Y[0, 8] = Convert.ToDateTime("2/23/2007 5:08:25 PM").ToOADate();     chart1.Data.YFrom[0, 9] = Convert.ToDateTime("2/23/2007 5:08:28 PM").ToOADate();   chart1.Data.Y[0, 9] = Convert.ToDateTime("2/23/2007 5:08:30 PM").ToOADate();   chart1.Data.YFrom[0, 10] = Convert.ToDateTime("2/23/2007 5:08:33 PM").ToOADate();   chart1.Data.Y[0, 10] = Convert.ToDateTime("2/23/2007 5:08:35 PM").ToOADate(); 

Link to comment
Share on other sites

If you want a scrolbar in your Y-Axis you must specify how much scroll do you want, in other words, you must specify how many pixels you want for each logical unit (1 day in this case). You do this by setting:

chart.AxisY.AutoScroll = true;

chart.AxisY.PixelsPerUnit = 100000;

You can also define PixelsPerUnit using the SetScrollView method:

chart1.AxisY.SetScrollView(new DateTime(2007,1,1,0,0,0).ToOADate(),new DateTime(2007,1,1,0,1,0).ToOADate());

In this case your range must be small enough to see 3 seconds.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...