Page 1 of 1

Retrieving Gantt bars from DBChart

Posted: Fri Jan 23, 2009 1:53 am
by 10551545
Hi,

I'd like to connect tasks in a gantt. I'm using data aware dbchart, so i thought this:

TChartSeries* myseries;
for(int i = 0; i<ChartListBox->Count; i++){
if(ChartListBox->Series->Active){
myseries = ChartListBox->Series;
break;
}
}
TGanttSeries* xseries = dynamic_cast<TGanttSeries*>(myseries);
if(xseries){
xseries->NextTask[0] = 1; //1. compiler error
xseries->NextTask->Items[0] = 1; //2. does nothing
}

which is how i understand the delphi code example in the help. Here I'm assuming 0 is the first gantt bar, 1 the next etc.

However, for code line 1) the compiler complains it could not find a match for operator TChartValueList::=(int)?,
and 2 does nothing.

Better yet, click a bar, (ctrl) click another bar, release ctrl, to join them graphically. Perhaps i'm being overly optimistic! :-)


All help appreciated.

Cheers, nile.

Posted: Fri Jan 23, 2009 9:19 am
by narcis
Hi nile,
However, for code line 1) the compiler complains it could not find a match for operator TChartValueList::=(int)?,
and 2 does nothing.
You need to do this:

Code: Select all

		Series1->NextTask->Value[i]=-1;
Better yet, click a bar, (ctrl) click another bar, release ctrl, to join them graphically. Perhaps i'm being overly optimistic!
Not at all! You can do something like this:

Code: Select all

void __fastcall TForm4::FormCreate(TObject *Sender)
{
	Series1->FillSampleValues();

	//Reset all NextTastk values
	for (int i = 0; i < Series1->Count(); i++) {
		Series1->NextTask->Value[i]=-1;
	}

	BarIndex=-1;
}
//---------------------------------------------------------------------------
void __fastcall TForm4::Series1Click(TChartSeries *Sender, int ValueIndex, TMouseButton Button,
		  TShiftState Shift, int X, int Y)
{
	if (BarIndex==-1) {
		BarIndex=ValueIndex;
	}
	else
	{
		if (Shift.Contains(ssCtrl)) {
			Series1->NextTask->Value[BarIndex]=ValueIndex;
			Series1->Repaint();
			BarIndex=-1;
		}
	}
}
Hope this helps!

Posted: Fri Jan 23, 2009 9:44 pm
by 10551545
Hi Narcis,

Thanks and nicely done - but there is a problem. First, because i'm using a dbchart, i don't have access to the onclick event of a specific chart. No problem, i can get this using the ChartClickSeries event. However, when running the code, I can click on some bars, and the event fires. However i click on other bars, and no event fires. What am i doing wrong?

Thanks,
nile.

void __fastcall TChartsNew::ChartClickSeries(TCustomChart *Sender,
TChartSeries *Series, int ValueIndex, TMouseButton Button,
TShiftState Shift, int X, int Y)
{

TGanttSeries* myseries;

if(Series->Name == "GanttChart"){
myseries = dynamic_cast<TGanttSeries*>(Series);
if(!myseries) return;

if (BarIndex==-1) {
BarIndex=ValueIndex;
}
else
{
if (Shift.Contains(ssCtrl)) {
myseries->NextTask->Value[BarIndex]=ValueIndex;
myseries->Repaint();
BarIndex=-1;
}
}
}
}

Posted: Mon Jan 26, 2009 9:27 am
by narcis
Hi nile,

This event is Series' OnClick event. Anyway you can use chart's OnClickSeries event and both events are available in TChart and TDBChart.

Your code works fine for me here. If problem persists could you please send us a simple example project we can run "as-is" to reproduce the problem here?

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.

Posted: Mon Jan 26, 2009 11:59 pm
by 10551545
Hi Narcis,

I've uploaded a 3mb monolithic plus project file zip. I'm using virtual tables for this exampled code. Just select the gantt, fill with act start/end and folder title in labels to see the issues with joining bars.

Thanks, nile.

Posted: Tue Jan 27, 2009 9:27 am
by narcis
Hi nile,

Thanks for the example project. I couldn't compile it here because it uses TSMDBGrid and TVirtualTable components which we don't have here. Also, running the exe you sent, I didn't see any problem in it. Could you please let us know which is the exact problem and the exact steps we should follow to reproduce it? You may also want to send us a simple example project we can run "as-is" so that we can debug it here.

Thanks in advance.

Posted: Tue Jan 27, 2009 6:35 pm
by 10551545
Hi Narcis,

Ah, this is promising. If the exe ran as you expected, then perhaps i'm doing it wrong. I understood that you clicked a bar in the gantt, and then using ctrl, clicked another bar to join them up. When i do this on the exe i sent you, it's quite a hit and miss affair. So perhaps this is where i'm falling over.

Thanks, nile.

Posted: Wed Jan 28, 2009 9:09 am
by narcis
Hi nile,

Yes, exactly, that's how it works. This works fine for me here as you can see in the video below. You'll have to open it in Internet Explorer.

http://www.teechart.net/files/public/su ... e.swf.html

Could you please let us know the exact steps we should follow to reproduce the issue here?

Thanks in advance.

Posted: Wed Jan 28, 2009 7:43 pm
by 10551545
Hi Narcis,

Fabulous demo! I can clearly see why i was being unsuccessful, as you have to be quite precise in where you position the mouse cursor prior to selecting: specifically on the actual bar, and NOT on the depth rendering, as i think i was doing.

Many thanks, Nile.

Posted: Thu Jan 29, 2009 9:20 am
by narcis
Hi Nile,

You're welcome. I'm glad to hear that helped.

Yes, you need to use as if it were a 2D chart. Setting the chart to be 2D may make things easier:

Code: Select all

Chart1->View3D=false;