0
votes

I would like to ask some help on displaying my datasource’s clientname at the bottom of my stacked bar chart. It seems from all the examples that I researched, the bottom chart axis label is set "automatically" by TeeChart looking at the datasource. However I cant seem to get it to work. Below is a picture of what I am trying to achieve.

Picture of what I am trying to achieve

I have three series' which I use to build the stacked chart. I have included a picture of each datasource I use for each query.

Datasources for three series' queries

From my research it seems I can also use the DBChart1GetAxisLabel() to custom set the labels. But I am struggling to understand how to ensure that the correct custom label name is associated with the correct "clientname" from my queries.

Here is a code sample of how I build the charts:

    procedure TfrmSupplierAnalytics.btnOKClick(Sender: TObject);
    var
      S,NewTypeStr, test, clientSql : string;
      var seriasNormalOrders:TBarSeries;
      var seriasCreditNoteOrders:TBarSeries;
      var seriasPartialOrders:TBarSeries;
      N, i : integer;
    begin
       qCreditNoteOrders.Close;
       qNormalOrders.Close;
       qPartialOrders.Close;
       qGetClientIdFromName.Close;
       qClients.Close;

       DBChart1.CleanupInstance;
       DBChart1.ClearChart;

       try
          for N := 0 to clbClients.Items.Count-1 do
            if clbClients.State[N] = cbChecked then begin
              test :=  string(clbClients.Items[N]);
              NewTypeStr := NewTypeStr + '(E.clientid  = '+ 
    IntToStr(FindClientID(test)) + ')';
              clientSql := clientSql +  NewTypeStr;
              NewTypeStr := ' or ';
            end;
          except
             on E : Exception do
              ShowMessage(E.ClassName+' error raised, with message : 
    '+E.Message);
          end;

       OpenQueryCreditNoteOrders(clientSql);
       OpenQueryPartialOrders(clientSql);
       OpenQueryNormalOrders(clientSql);

       seriasNormalOrders :=TBarSeries.Create(self);
       DBChart1.AddSeries(seriasNormalOrders);

       seriasCreditNoteOrders :=TBarSeries.Create(self);
       DBChart1.AddSeries(seriasCreditNoteOrders);

       seriasPartialOrders :=TBarSeries.Create(self);
       DBChart1.AddSeries(seriasPartialOrders);

       seriasNormalOrders.MultiBar := mbStacked;
       seriasCreditNoteOrders.MultiBar := mbStacked;
       seriasPartialOrders.MultiBar := mbStacked;

       seriasNormalOrders.Marks.Visible := true;
       seriasNormalOrders.MarksLocation:= mlCenter;
       seriasNormalOrders.MarksOnBar := True;

       seriasNormalOrders.YValues.ValueSource := 'NormalOrders';
       seriasNormalOrders.DataSource := qNormalOrders;
       seriasNormalOrders.Title := 'Correct Orders';
       seriasNormalOrders.Marks.Visible := True;
       seriasNormalOrders.Marks.AutoPosition := true;

       seriasCreditNoteOrders.YValues.ValueSource := 'CreditNoteOrders';
       seriasCreditNoteOrders.DataSource := qCreditNoteOrders;
       seriasCreditNoteOrders.Title := 'Credit Note Orders';

       seriasPartialOrders.YValues.ValueSource := 'PartialOrders';
       seriasPartialOrders.DataSource := qPartialOrders;
       seriasPartialOrders.Title := 'Short Orders';

       seriasNormalOrders.CheckDataSource;
       seriasCreditNoteOrders.CheckDataSource;
       seriasPartialOrders.CheckDataSource;
     end;

So, just to sum up, is there some setting in my code which I am missing that would show the "clientname" below each stacked bar, or must I use custom labels? If I must use custom labels, I would appreciate some direction on how to ensure that I replace the correct "clientname" from the datasource to the correct ValueIndex in the DBChart1GetAxisLabel?

Thanks in advance.

1
Hello Johan, Could you tell us what is the TeeChart VCL/FMX are you using?Sandra Pazos
Hi, I am using Embarcadero RAD Studio XE2 with VCL forms. So, from my uses section in the code I see the 'VCLTee.*****' is being implemented. I am using Steema version: TeeChart VCL/FMX version 2018 Build 2018.24.180321.Johan van der Merwe

1 Answers

1
votes

I managed to get an answer.

You could set the XLabelsSource to show the text from the DataSource and then set the series Marks.Style to smsValue to force it showing values instead of showing the labels. Ie:

<pre>
procedure TForm1.FormCreate(Sender: TObject);
var ADOQuery1: TADOQuery;
i: Integer;
begin
ADOQuery1:=TADOQuery.Create(Self);
with ADOQuery1 do
begin
ConnectionString:='Provider=MSDASQL.1;Persist Security Info=False;Data 
Source=TeeChart Pro Database';
SQL.Add('SELECT SALARY, LASTNAME from Employee WHERE LASTNAME='#39'Smith'#39);
end;

for i:=0 to 1 do
with DBChart1.AddSeries(TBarSeries) as TBarSeries do
begin
XLabelsSource:='LASTNAME';
DataSource:=ADOQuery1;
MultiBar:=mbStacked;
YValues.ValueSource:='SALARY';

Marks.Style:=smsValue;
end;

ADOQuery1.Open;
end;
</pre>

I tested it in my project and it works.