TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
henry20
- Newbie
- Posts: 2
- Joined: Thu Mar 24, 2016 12:00 am
Post
by henry20 » Mon Nov 14, 2016 1:08 pm
Hello everyone,
i'm developping a simple project management app in C++ Builder 10 and i'm using the gantt chart for the task management.
I'm able to draw the gantt bar but i have a problem updating or rather deleting the old one for a new one. Let me explain further so it can be a little more clearer. I have a TStringgrid which contains a name of the task, the starting and the ending date of the task. The end user can create as much tasks as he/she wants, and i want essentially to update the bar each time the user click on a row, i.e. if the user clicks row 1 i want to display the gantt bar of task 1 with the starting and end date of the task 1, if it's row 5 which is selected it will be the gantt bar of task 5 with the starting and end date of the task 5. Each time the user clicks a new row the old one would be deleted and redrawed. To simplify this task i created a method which is called each time the user clicks a row. I tried it with Series.Clear() method but it don't get the result i want.
Code: Select all
// This function is called each time the user clicks a row
void MainClass::drawgantt(TDate startdate,TDate enddate, int task, String nametask)
{
TGanttSeries *Series1;
Series1 = new TGanttSeries(this);
Series1->AddGantt(startdate, enddate, task,nametask);
Series1->ParentChart = Chart1;
}
How can i realize this by modifying this drawgantt method? If you need more information don't hesitate ask and i will answer. I hope i'm clear because english is not my mothertongue.
Thank you very much
-
Yeray
- Site Admin
- Posts: 9614
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Mon Nov 14, 2016 2:51 pm
Hello,
I'm not sure if this is what you'd like to achieve:
Code: Select all
uses DateUtils, GanttCh;
var gantt1: TGanttSeries;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
tmpDate1, tmpDate2: TDateTime;
begin
Chart1.Legend.Visible:=false;
Chart1.View3D:=false;
gantt1:=Chart1.AddSeries(TGanttSeries) as TGanttSeries;
StringGrid1.ColCount:=3;
StringGrid1.RowCount:=5;
StringGrid1.Cells[0,0]:='Task';
StringGrid1.Cells[1,0]:='Start';
StringGrid1.Cells[2,0]:='End';
for i:=1 to StringGrid1.RowCount-1 do
begin
StringGrid1.Cells[0,i]:=IntToStr(i);
tmpDate1:=Today+random(10);
tmpDate2:=IncDay(tmpDate1,random(10));
StringGrid1.Cells[1,i]:=DateToStr(tmpDate1);
StringGrid1.Cells[2,i]:=DateToStr(tmpDate2);
gantt1.AddGantt(tmpDate1, tmpDate2, i);
end;
Chart1.Axes.Bottom.SetMinMax(gantt1.StartValues.MinValue-1, gantt1.EndValues.MaxValue+1);
Chart1.Axes.Left.SetMinMax(gantt1.YValues.MinValue-0.5, gantt1.YValues.MaxValue+0.5);
gantt1.Clear;
end;
procedure TForm1.StringGrid1Click(Sender: TObject);
var tmpDate1, tmpDate2: TDateTime;
tmpValue: Integer;
begin
gantt1.Clear;
if StringGrid1.Row>0 then
begin
tmpDate1:=StrToDate(StringGrid1.Cells[1,StringGrid1.Row]);
tmpDate2:=StrToDate(StringGrid1.Cells[2,StringGrid1.Row]);
tmpValue:=StrToInt(StringGrid1.Cells[0,StringGrid1.Row]);
gantt1.AddGanttColor(tmpDate1, tmpDate2, tmpValue,'',OperaPalette[tmpValue]);
end;
end;