How to dislay correct x-axis (bottom axis) label from datasource using Teechart (Delphi)

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Johan vd Merwe
Newbie
Newbie
Posts: 2
Joined: Tue Jul 24, 2018 12:00 am
Location: South Africa
Contact:

How to dislay correct x-axis (bottom axis) label from datasource using Teechart (Delphi)

Post by Johan vd Merwe » Mon Aug 20, 2018 10:33 am

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. I am using Rad Studio XE2 and VCL forms.

I have attached two images of what I am trying to achieve, and an example of my three datasources (from DB).
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.

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:

Code: Select all

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.
Attachments
What I want to achieve.png
What I want to achieve.png (228.76 KiB) Viewed 8209 times

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: How to dislay correct x-axis (bottom axis) label from datasource using Teechart (Delphi)

Post by Yeray » Wed Aug 22, 2018 8:31 am

Hello,

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:

Code: Select all

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Johan vd Merwe
Newbie
Newbie
Posts: 2
Joined: Tue Jul 24, 2018 12:00 am
Location: South Africa
Contact:

Re: How to dislay correct x-axis (bottom axis) label from datasource using Teechart (Delphi)

Post by Johan vd Merwe » Wed Aug 22, 2018 10:24 am

Hi Yeray

Thanks a lot! This solved the issue for me.

Regards

Johan

Post Reply