1

I'm using a TDBChart - from TeeChart Std to display a pie chart that does a SUM of values from my PRICE column inside the db I'm using and it's sorting the data on Months - from a DATE column that's set as datetime type in the database.

My TDBChart displays the following:

enter image description here

My problem: How do I make it display the month as October-2016 and November-2016

(idealy Oct-16 and Nov-16 respectively).

As you can see, it's currently displaying it as numbers - 10-16 and 11-16.

Can't seem to find a Format option for this anywhere inside the series options.

t1f
  • 3,021
  • 3
  • 31
  • 61

1 Answers1

2

I would format the datetime as a string before adding the points and I would pass it as a label. Ie:

uses DateUtils;

procedure TForm1.FormCreate(Sender: TObject);
var tmpDate: TDateTime;
    i: Integer;
begin
  for i:=0 to 1 do
  begin
    tmpDate:=IncMonth(Today,i);
    Series1.AddPie(random*100,FormatDateTime('mmm-yy', tmpDate));
  end;
end;

EDIT:

If you are populating connecting it to a datasource, then the labels are automatically added. Then, the only option I see without modifying the sources would be to use the OnGetMarkText event as follows:

procedure TForm1.Series1GetMarkText(Sender: TChartSeries; ValueIndex: Integer;
  var MarkText: string);
var i: Integer;
    m, y: string;
begin
  i:=Pos('-',MarkText);
  m:=Copy(MarkText,1,i-1);
  y:=Copy(MarkText,i+1,Length(MarkText)-i);
  MarkText:=ShortMonthNames[StrToInt(m)] + ' ' + y;
end;
Yeray
  • 5,009
  • 1
  • 13
  • 25
  • I add the information directly using the DataSource tab, Summary and then setting my TSimpleDataSet there. If I understand your suggestion correctly I can't "add points and pass it as a label" this way, or did I understand what you're proposing, wrong? – t1f Nov 29 '16 at 13:44
  • Hi, thanks for the addition to the answer! I don't have that Event available in the Object Inspector list when selecting the DBChart in question. I notice it is a Series event, how do I access those? Select the series inside my DBChart doesn't produce an Event list in the Object Inspector – t1f Nov 30 '16 at 10:54
  • You can select the series in the Object Inspector (click on the form to change the focus and the object inspector will be refreshed adding the series to the combobox). Alternatively, you can declare the event manually and assign the event at runtime doing this at `FormCreate`: `Series1.OnGetMarkText:=Series1GetMarkText;` – Yeray Dec 02 '16 at 08:35
  • Thanks, worked like a charm, one issue: ShortMonthNames says underclared identifier, I fixed it by adding FormatSettings, like this: `MarkText:=FormatSettings.ShortMonthNames[StrToInt(m)] + ' ' + y;` hope it's ok :) – t1f Dec 02 '16 at 15:19