Page 1 of 1

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

Posted: Sun Mar 20, 2022 8:08 pm
by 16892633
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

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

Posted: Wed Mar 23, 2022 8:12 am
by Marc
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