t1f
t1f

Reputation: 3181

Change TDBChart Month format display

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.

Upvotes: 1

Views: 379

Answers (1)

Yeray
Yeray

Reputation: 5039

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;

Upvotes: 2

Related Questions