How to set the MarkText of each chart point from a Query

TeeChart FireMonkey (Windows,OSX,iOS & Android) for Embarcadero RAD Studio, Delphi and C++ Builder (XE5+)
Post Reply
PCSdeZ
Newbie
Newbie
Posts: 18
Joined: Thu Dec 16, 2021 12:00 am

How to set the MarkText of each chart point from a Query

Post by PCSdeZ » Sun Mar 20, 2022 8:08 pm

Hi,

I'm working with a TDBChart and a TFDQuery as a DataSource with three data fields: Date, Amount and ItemName. I'm using C++ Builder 11 and FMX.

I'm trying to make a Bar chart with Date on the XValue, Amount on YValue, and I want the ItemName as XLabel, but I didn't found the way to do that.

The chart always shows the Value or the Label as XLabelSource. To show the ItemName I'm trying with OnGetMarkText event handler, but I don't know how to access the ItemName inside the event handler. This is the code that I'm testing:

.h code
----------

Code: Select all

void __fastcall DefinicionMarcasSeriesCLP(TChartSeries *Sender, int ValueIndex, UnicodeString &MarkText);
.cpp code
-------------

Code: Select all

void __fastcall TForm_GraficosFlujoCaja::FormShow(TObject *Sender)
{
   TChartSeries *SerieFlujoCajaCLP = DBChart_FlujoCaja->Series[0];
   SerieFlujoCajaCLP->OnGetMarkText = DefinicionMarcasSeriesCLP;
}

void __fastcall TForm_GraficosFlujoCaja::DefinicionMarcasSeriesCLP(TChartSeries *Sender, int ValueIndex, UnicodeString &MarkText)
{
	if(Sender != NULL && ValueIndex > -1) {
		MarkText = IntToStr(ValueIndex); // Here I want the ItemName: How could do it?
	}
}
Could you give me some tips please?

Best regards,
Patricio Cerda

Marc
Site Admin
Site Admin
Posts: 1274
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: How to set the MarkText of each chart point from a Query

Post by Marc » Wed Mar 23, 2022 8:12 am

Hello Patricio,

Here are the fieldnames for a Bar Series example setup via the Chart Editor to use the Embarcadero DBDemos' Orders table. You can use the same properties by code if you wish, including XLabelsSource:

Code: Select all

    object Series1: TBarSeries
      DataSource = FDQuery1
      XLabelsSource = 'ShipVIA'
      XValues.DateTime = True
      XValues.Name = 'X'
      XValues.Order = loAscending
      XValues.ValueSource = 'ShipDate'
      YValues.Name = 'Bar'
      YValues.Order = loNone
      YValues.ValueSource = 'AmountPaid'
    end
Regards,
Marc
Steema Support

Post Reply