Q:

Tchart change labels

I need a little help on changing the labels shown on a tchart
I use this code to populate the tchart:
   With Series1 do
    begin
     clear;
     Add (v[1], 'abcdef', clRed);
     Add (v[2], 'aaaaaaaaaaaaaaaaaaaaaaaa', clBlue);
     Add (v[3], 'bbbbbbbbbbbbbb', clGreen);
    end;

I get this chart:
image of chart
Please help me on changing the labels above the rectangles from the text shown in the image to some other variables via code; also please tell me what can i do to show long texts on the x axis and how to break it on multiple lines

A:

First, I'll assume that your "v" variable was an array of integer; My example it's named "BarValue".  The form has a TChart with a 2D Bar Series added.
When you construct the labels, you'll want to replace the spaces and word-breaks with the "TeeLineSeparator" and then maybe rescan them and insert in a "TeeLineSeparator" into much longer words to force them to line-break. (In my example I just broke the long "aaaaaaaaa..." label into words randomly.)
This example worked in the Delphi 10.2 Tokyo and Delphi 2007.
type    
  TForm1 = class(TForm)
    Chart1: TChart;
    Series1: TBarSeries;

    procedure FormCreate(Sender: TObject);
    procedure Series1GetMarkText(Sender: TChartSeries; ValueIndex: Integer; var MarkText: string);

  private
   BarMark : array[1..3] of string;
   BarValue : array[1..3] of integer;
   BarLabel : array[1..3] of string;
   BarColor : array[1..3] of TColor;
  end;

procedure TForm1.FormCreate(Sender: TObject);

var
   i : integer;

begin
   Chart1.Legend.Visible := false;

   // This maybe needed on earlier versions of TChart (e.g. Delphi 2007-)
   //   to make room for multi-line labels
   //Chart1.Axes.Bottom.LabelSize := 32;

   Series1.OnGetMarkText := Series1GetMarkText;

   BarValue[1] := 100;
   BarValue[2] := 200;
   BarValue[3] := 300;

   BarLabel[1] := 'abcdefg';
   BarLabel[2] := 'aaaa'+TeeLineSeparator+'aaaaaaaaa'+TeeLineSeparator+'aaaaaaaaaaa';
   BarLabel[3] := 'bbbbbbbbbbbbbb';

   BarColor[1] := clRed;
   BarColor[2] := clBlue;
   BarColor[3] := clGreen;

   BarMark[1] := 'ok1';
   BarMark[2] := 'ok2';
   BarMark[3] := 'ok3';

   Series1.Clear;
   for i := 1 to 3 do
      Series1.Add (BarValue[i], BarLabel[i], BarColor[i]);
end;

procedure TForm1.Series1GetMarkText(Sender: TChartSeries; ValueIndex: Integer; var MarkText: string);

begin
   MarkText := BarMark[ValueIndex+1];
end;

The DFM:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 374
  ClientWidth = 702
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Chart1: TChart
    Left = 204
    Top = 40
    Width = 400
    Height = 250
    Title.Text.Strings = (
      'TChart')
    View3D = False
    TabOrder = 0
    DefaultCanvas = 'TGDIPlusCanvas'
    ColorPaletteIndex = 13
    object Series1: TBarSeries
      OnGetMarkText = Series1GetMarkText
      XValues.Name = 'X'
      XValues.Order = loAscending
      YValues.Name = 'Bar'
      YValues.Order = loNone
    end
  end
end

