Chart.Draw with LabelStyle talText - BottomAxis missing

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Jamie
Newbie
Newbie
Posts: 21
Joined: Thu Mar 17, 2022 12:00 am

Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Jamie » Wed Oct 26, 2022 8:58 am

Hi,

I have recently updated to TeeChart 2022.36 with Delphi 10.4.

Now that I have updated TChart I find that all my "Chart.Draw" calls now have a missing BottomAxis.

This is affecting several different applications, which I have been maintaining for years, through multiple previous upgrades of TeeChart.

This turns out to be because I am using "BottomAxis.LabelStyle := talText;" and GetAxisLabel to populate the labels.

Even with simple, short, test code I cannot get the BottomAxis to display anything at all when using Chart.Draw with talText.

Please find a sample attached. In this example I can step through the GetAxisLabel code and see a value being assigned to LabelText, but the bottom axis is still entirely missing.

Thanks,
Jamie
Attachments
Project2.zip
(1.48 KiB) Downloaded 830 times

Jamie
Newbie
Newbie
Posts: 21
Joined: Thu Mar 17, 2022 12:00 am

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Jamie » Wed Oct 26, 2022 6:59 pm

I have tried everything I can think of to get the axis to draw, so far to no avail.

I have found a sort-of-workaround using "Chart.BottomAxis.Items.Add", which does display. But I am using GetAxisLabel to dynamically vary the number of labels displayed on a whole DrawGrid full of charts, as the form resizes. So it would be far from ideal to have to repopulate the bottom axis of every chart on the fly!

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

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Yeray » Thu Oct 27, 2022 11:40 am

Hello,

LabelStyle talText forces the axes to show the labels from the first series assigned to the axis. However, in that example you have no labels in your series. That's why no labels are drawn.

Assigning labels to the series, you don't even need to use OnGetAxisLabel event:

Code: Select all

procedure TForm2.Button2Click(Sender: TObject);
var
  Rect: TRect;
  i: Integer;
begin
  Chart := TChart.Create(Self);
  Chart.View3D := False;
  Chart.BottomAxis.LabelStyle := talText;
  //Chart.OnGetAxisLabel := ChartGetAxisLabel;
  Chart.AddSeries(TBarSeries.Create(Chart));
  Chart.SeriesList[0].FillSampleValues(48);

  for i:=0 to Chart[0].Count-1 do
    Chart[0].Labels[i]:='Idx '+IntToStr(i);

  Rect := Image1.ClientRect;
  Chart.Draw(Image1.Canvas, Rect);
  Chart.Free;
  Image1.Refresh;
end;
Project2_2022-10-27_13-39-20.png
Project2_2022-10-27_13-39-20.png (41.41 KiB) Viewed 14207 times
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

Jamie
Newbie
Newbie
Posts: 21
Joined: Thu Mar 17, 2022 12:00 am

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Jamie » Thu Oct 27, 2022 12:43 pm

Hi Yeray,

Thanks, but as I said in my second post this doesn't help me.

The change to TeeChart breaks existing code, which needs to dynamically adjust the bottom axis for sometimes over 100 charts on the screen at any time. OnGetAxisLabel is fired as the chart gets redrawn, whereas clearing and repopulating the axis for each chart is more cumbersome and less flexible.

If I assign any items to Chart.BottomAxis.Items then the string returned by OnGetAxisLabel is not shown.

What is the point of OnGetAxisLabel if it cannot change what is displayed?

Thanks,
Jamie

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

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Yeray » Thu Oct 27, 2022 12:59 pm

Hello Jamie,

My suggestion is to populate the series labels instead of using OnGetAxisLabel or Chart.BottomAxis.Items.
This should internally recalculate the labels to be drawn depending on the axis size.
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

Jamie
Newbie
Newbie
Posts: 21
Joined: Thu Mar 17, 2022 12:00 am

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Jamie » Thu Oct 27, 2022 1:23 pm

Hi Yeray,

Thanks, but because some of the labels are times and other values that have meaning the automatically calculated increments do not always make sense and customers have said so - hence I overrode it with my own algorithm, which my customers are happy with.

I say again though: why has OnGetAxisLabel stopped working? It now serves no purpose!

Why has this changed and broken my existing code, which has worked this way for over 10 years?

In that time I have upgraded TChart several times without it breaking before.

Jamie
Newbie
Newbie
Posts: 21
Joined: Thu Mar 17, 2022 12:00 am

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Jamie » Thu Oct 27, 2022 3:39 pm

OK, further to my last post, I just checked the latest Help chm file I downloaded and the description for OnGetAxisLabel still matches what I am trying to do.

Surely this is a bug, as this function no longer works?

I can see my code assigning values to LabelText, as shown, but they do no appear.
Attachments
GetAxisLabel.png
GetAxisLabel.png (31.96 KiB) Viewed 14200 times

Jamie
Newbie
Newbie
Posts: 21
Joined: Thu Mar 17, 2022 12:00 am

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Jamie » Thu Oct 27, 2022 3:47 pm

... third post!

I should also point out, in answer to your point that the axis doesn't display because I have not added any labels, that OnGetAxisLabel is not called at all if I add even a single label to "BottomAxis.Items".

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

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Yeray » Wed Nov 02, 2022 12:07 pm

Hello Jamie,

I've been trying your test app with previous TeeChart versions (v2021.33 to v2022.36) with the same results. In what version do you find it behaved differently?
I'll be glad to investigate any braking change you may identify.

Indeed, if I add a custom item to the bottom axis, OnGetAxisLabel is not being fired, but the custom item is drawn, so you should be able to implement your algorithm with custom items. Ie:

Code: Select all

procedure TForm2.Button2Click(Sender: TObject);
var
  Chart: TChart;
  Rect: TRect;
begin
  Chart := TChart.Create(Self);
  Chart.View3D := False;
  //Chart.BottomAxis.LabelStyle := talText;

  Chart.BottomAxis.Items.Add(5, 'five');
  Chart.BottomAxis.Items.Add(10, 'ten');
  Chart.BottomAxis.MinorTicks.Hide;

  //Chart.OnGetAxisLabel := ChartGetAxisLabel;
  Chart.AddSeries(TBarSeries.Create(Chart));
  Chart.SeriesList[0].FillSampleValues(48);
  Rect := Image1.ClientRect;
  Chart.Draw(Image1.Canvas, Rect);
  Chart.Free;
  Image1.Refresh;
end;
custom items.png
custom items.png (35.37 KiB) Viewed 14037 times
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

Jamie
Newbie
Newbie
Posts: 21
Joined: Thu Mar 17, 2022 12:00 am

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Jamie » Sun Nov 06, 2022 9:24 pm

Hi Yeray,

I assign the same OnGetAxisLabel procedure to between 50 and 1000 charts in a grid, which automatically refresh the axis labels as the grid scrolls/resizes and the charts redraw, which seems a nice solution. I would prefer, if possible, not to risk introducing any bugs by changing the method, as the software runs 24/7, recording data.

Unfortunately in my many attempts to get the latest TeeChart version working with QuickReport I uninstalled all my previous versions of TeeChart for the other Delphi versions I have on my current development machines, so I can't say what the latest version was that OnGetAxisLabel was working with. I daren't try reinstalling any older versions, in case it breaks what took me weeks to get working!

I have booted up some older versions of Delphi on an old PC and my previous laptop and can confirm that the code I uploaded works as expected on the following TeeChart versions :-
Delphi XE2 : "TeeChart Standard v2011.03.32815 32bit VCL"
Delphi XE7 : "TeeChart Pro v2017.22.170619 32bit VCL"

Thanks,
Jamie

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

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Yeray » Mon Nov 07, 2022 10:32 am

Hello Jamie,
Jamie wrote:
Sun Nov 06, 2022 9:24 pm
Delphi XE7 : "TeeChart Pro v2017.22.170619 32bit VCL"
Thanks to this I found the issue you are experiencing was introduced with the fix for #1899.
We'll check if there's anything wrong with it.
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

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

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Yeray » Mon Nov 07, 2022 2:18 pm

Hello Jamie,

I've added it to the public tracker and already fixed it for the next maintenance release:
https://www.steema.com/bugs/show_bug.cgi?id=2565

Since you own the sources, you can apply the fix to your copy without waiting for the next release. At TeEngine.pas, substitute the CalcFirstLastAllSeries method for this:

Code: Select all

    procedure CalcFirstLastAllSeries(out tmpFirst,tmpLast:Integer);
    var t : Integer;
    begin
      tmpFirst:=High(Integer);
      tmpLast:=-1;

      for t:=0 to ISeriesList.Count-1 do
      with ISeriesList[t] do
      begin
        if (FLabels.Count>0) or (LabelStyle=talPointValue) or Assigned(ParentChart.FOnGetAxisLabel) then
        begin
          CalcFirstLastVisibleIndex;

          if (FFirstVisibleIndex<tmpFirst) and (FFirstVisibleIndex<>-1) then
             tmpFirst:=FFirstVisibleIndex;

          if FLastVisibleIndex>tmpLast then
             tmpLast:=FLastVisibleIndex;
        end;
      end;
    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

Jamie
Newbie
Newbie
Posts: 21
Joined: Thu Mar 17, 2022 12:00 am

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Jamie » Tue Nov 08, 2022 2:48 pm

Hi Yeray,

Many thanks for your help. Unfortunately that doesn't seem to have solved the problem for me, but perhaps I'm missing something?

I made the change you suggested in TeEngine.pas and VCLTee.TeEngine.pas (just to be sure) and ran TeeRecompile, but I'm not seeing any change in the behaviour of my Project2 test code.

Is there something else I need to do?

Thanks again,
Jamie

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

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Yeray » Wed Nov 09, 2022 10:28 am

Hello Jamie,

This is how your project looks for me after the change:
Project2_2022-11-09_11-24-52.png
Project2_2022-11-09_11-24-52.png (38.98 KiB) Viewed 13923 times
Make sure you are rebuilding the project after applying the change.
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

Jamie
Newbie
Newbie
Posts: 21
Joined: Thu Mar 17, 2022 12:00 am

Re: Chart.Draw with LabelStyle talText - BottomAxis missing

Post by Jamie » Wed Nov 09, 2022 4:54 pm

Hi Yeray,

Apologies, I made a silly mistake!

I edited the files, as stated, I ran TeeRecompile, I rebuilt the project ... but I had put the modified TeEngine.pas in the same directory as VCLTee.TeEngine.pas!

Hence TeeRecompile was still finding the old version of TeEngine.pas.

The project now works as expected and I can finally issue a product update.

Thanks again for your continued help.

All the best,
Jamie

Post Reply