Page 1 of 1

TDBChart in VCL

Posted: Mon Jun 26, 2017 6:01 pm
by 16479566
When using TDBChart in VCL I’m not getting the expected output. I get two separate X’s for the two series.
Works ok in FMX.

How to I resolve this?
Thanks, Alan

Code: Select all

// VCL
//---------------------------------------------------------------------------
void __fastcall TfMain::bChartClick(TObject *Sender)
{
 int i ;

 FDMemTable->EmptyDataSet() ;
 FDMemTable->Append() ;
 FDMemTable->FieldValues["ID"]     = 1 ;
 FDMemTable->FieldValues["Input"]  = 10 ;
 FDMemTable->FieldValues["Output"] = 20 ;

 FDMemTable->Append() ;
 FDMemTable->FieldValues["ID"]     = 2 ;
 FDMemTable->FieldValues["Input"]  = 20 ;
 FDMemTable->FieldValues["Output"] = 40 ;
 FDMemTable->Post() ;

 Series1->Clear() ;
 Series2->Clear() ;
 FDMemTable->First() ;

 do
  {
   Series1->AddXY(FDMemTable->FieldByName("ID")->AsInteger, FDMemTable->FieldByName("Input")->AsInteger, "", clBlack) ;
   Series2->AddXY(FDMemTable->FieldByName("ID")->AsInteger, FDMemTable->FieldByName("Output")->AsInteger, "", clBlack) ;

   FDMemTable->Next() ;
  }while(!FDMemTable->Eof) ;

}
//---------------------------------------------------------------------------
void __fastcall TfMain::bConnectClick(TObject *Sender)
{
 Series3->DataSource = FDMemTable ;
 Series4->DataSource = FDMemTable ;

 Series3->XLabelsSource = "ID" ;
 Series4->XLabelsSource = "ID" ;

 Series3->YValues->ValueSource = "Input" ;
 Series4->YValues->ValueSource = "Output" ;
}
//--------------------------------------------------------------------------

// FMX
//---------------------------------------------------------------------------
void __fastcall TfMain::bChartClick(TObject *Sender)
{
 int i ;

 BindSourceDB1->DataSource = 0 ;
 FDMemTable->EmptyDataSet() ;
 FDMemTable->Append() ;
 FDMemTable->FieldValues["ID"]     = 1 ;
 FDMemTable->FieldValues["Input"]  = 10 ;
 FDMemTable->FieldValues["Output"] = 20 ;

 FDMemTable->Append() ;
 FDMemTable->FieldValues["ID"]     = 2 ;
 FDMemTable->FieldValues["Input"]  = 20 ;
 FDMemTable->FieldValues["Output"] = 40 ;
 FDMemTable->Post() ;
 BindSourceDB1->DataSource = dsFDMemTable ;

 Series1->Clear() ;
 Series2->Clear() ;
 FDMemTable->First() ;

 do
  {
   Series1->AddXY(FDMemTable->FieldByName("ID")->AsInteger, FDMemTable->FieldByName("Input")->AsInteger, "", TAlphaColor(claBlack)) ;
   Series2->AddXY(FDMemTable->FieldByName("ID")->AsInteger, FDMemTable->FieldByName("Output")->AsInteger, "", TAlphaColor(claBlack)) ;

   FDMemTable->Next() ;
  }while(!FDMemTable->Eof) ;
}
//--------------------------------------------------------------------------
void __fastcall TfMain::bConnectClick(TObject *Sender)
{
 Series3->DataSource = FDMemTable ;
 Series4->DataSource = FDMemTable ;

 Series3->XLabelsSource = "ID" ;
 Series4->XLabelsSource = "ID" ;

 Series3->YValues->ValueSource = "Input" ;
 Series4->YValues->ValueSource = "Output" ;
}
//---------------------------------------------------------------------------

Re: TDBChart in VCL

Posted: Fri Jun 30, 2017 9:25 am
by yeray
Hello,

It sounds as a bug.
Could you please attach the projects so we can take a look at them?

Re: TDBChart in VCL

Posted: Fri Jun 30, 2017 2:03 pm
by 16479566
Here's the projects.

Re: TDBChart in VCL

Posted: Tue Jul 04, 2017 8:34 am
by yeray
Hello,

I haven't looked at the FMX version yet, but I see in the VCL version, this seems to fix the problem:

Code: Select all

 Series3->XValues->ValueSource = "ID";
 Series4->XValues->ValueSource = "ID";
Note you assigned the Labels and the YValues source of the series in the TDBChart, but not the XValues source.

Re: TDBChart in VCL

Posted: Tue Jul 04, 2017 9:20 am
by yeray
Hello,

I see in the dfm in your VCL project Series3 has XLabelSource and YValues.ValueSource defined.

Code: Select all

    object Series3: TLineSeries
      ...
      XLabelsSource = 'ID'
      ...
      YValues.ValueSource = 'Input'
Removing those 2 lines from the dfm the problem disappears.

Re: TDBChart in VCL

Posted: Thu Jul 06, 2017 8:47 pm
by 16479566
That works,

Thanks