After Hover, legend not shown with a single series

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Errol
Newbie
Newbie
Posts: 14
Joined: Fri Jul 08, 2016 12:00 am

After Hover, legend not shown with a single series

Post by Errol » Thu Nov 10, 2016 6:16 am

In July last year, I installed the latest version of TeeChart that highlights series when you hover over the legend. Very nice. However I notice over a year later that when there is only one series on the chart, the legend is not displayed. Is this an error or a feature? In either case, is there a way to always display the legend?

I look forward to your comments

Regards

Errol

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

Re: After Hover, legend not shown with a single series

Post by Yeray » Thu Nov 10, 2016 3:39 pm

Hi Errol,

I'm trying to reproduce this problem with the following code but I can see the legend as always with TeeChart v2016.19:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TBarSeries).FillSampleValues();
end;
Could you please arrange a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.
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

Errol
Newbie
Newbie
Posts: 14
Joined: Fri Jul 08, 2016 12:00 am

Re: After Hover, legend not shown with a single series

Post by Errol » Thu Nov 10, 2016 8:08 pm

Hi Yeray

Thanks for your reply. I do not have time right now to create a test program, but I have checked my old graphing code, which is unchanged between 16 July 2015 and 27 July 2015. In the interim I downloaded the latest TeeChart code, which introduced the Legend Hover Series Highlight feature. The legend works correctly before Hover was introduced, but does not display for single series after Hover is introduced. It seems clear that this is a TeeChart feature.

Regards

Errol

Errol
Newbie
Newbie
Posts: 14
Joined: Fri Jul 08, 2016 12:00 am

Re: After Hover, legend not shown with a single series

Post by Errol » Fri Nov 11, 2016 6:00 am

I put together the following test program. However, I cannot get the Hover functionality to work correctly, as the series is not highlighted. As you say, the legend is displayed with a single series, but perhaps not if Hover is working correctly. As the legend stopped working correctly after TeeChart was updated to the Hover version, with no changes in my graphing code, then it seems it is a TeeChart effect.

Regards

Errol

Code: Select all

unit LegendTestMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeeGDIPlus, ExtCtrls, TeeProcs, TeEngine, Chart, DBChart, Series,
  StdCtrls;

type
  TForm1 = class(TForm)
    DBChart1: TDBChart;
    Button1: TButton;
    Button2: TButton;
    procedure LoadData(Sender: TObject);
    procedure ClearData(Sender: TObject);
  private
    { Private declarations }

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ClearData(Sender: TObject);
begin
  DBChart1.RemoveAllSeries;
end;

procedure TForm1.LoadData(Sender: TObject);
begin
  DBChart1.Hover.Visible := True;
  DBChart1.AddSeries(TLineSeries).FillSampleValues();
end;

end.

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

Re: After Hover, legend not shown with a single series

Post by Yeray » Fri Nov 11, 2016 2:23 pm

Hi Errol,

I can't reproduce the problem.
Are you using the latest version available v2016.19?
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

Errol
Newbie
Newbie
Posts: 14
Joined: Fri Jul 08, 2016 12:00 am

Re: After Hover, legend not shown with a single series

Post by Errol » Sat Mar 04, 2017 5:35 am

I have carefully reviewed the response of my program to a single series before and after installation of TeeChart 2015.15, with the following results:
1. Program build date: 16 July 2015. Legend displayed with a single series in graph.
2. Download and install of TeeChart Pro VCL Source Code 2015.15: 17 July 2015.
3. Program build date: 27 July 2015. Legend not displayed with a single series in graph.

I have backup copies of the code for both builds. 8 files have changed, and none of them make any changes to graphing. Therefore it seems that this change in behaviour is caused by changes in TeeChart. I am unable to reproduce this behaviour with a simple test program. However, our program uses datasets and data sources directly from a relational database, so it seems that the error only appears with a more complicated type of graph. I am now using TeeChart 2016.19.

The errant behaviour appears to occur in CalcTotalItems in Chart.pas. If there are two or more active series with ShowInLegend then my code sets InternalLegendStyle = lsSeries and the code below is run, returning the correct result.

Code: Select all

      if (InternalLegendStyle=lsSeries) or (InternalLegendStyle=lsLastValues) then
      begin
        for t:=0 to TCustomChart(ParentChart).SeriesCount-1 do
        begin
          With TCustomChart(ParentChart).Series[t] do
               if (CheckBoxes or Active) and ShowInLegend then
                  Inc(result);
        end;
        Dec(result,FirstValue)
However, if there is only one active series with ShowInLegend then my code sets InternalLegendStyle = lsValues, the next bit of code below runs and returns result = 0.

Code: Select all

        tmpSeries:=GetLegendSeries;

        if Assigned(tmpSeries) and tmpSeries.ShowInLegend then
        begin
          if TSeriesAccess(tmpSeries).InvertedLegend then
             tmpInverted:=not tmpInverted;

          result:=tmpSeries.CountLegendItems-FirstValue;
        end;
I do not understand why there is no legend if InternalLegendStyle = lsValues. Is this the cause of the error?

I look forward to your reply.

Best regards

Errol

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

Re: After Hover, legend not shown with a single series

Post by Yeray » Tue Mar 07, 2017 9:30 am

Hello,

Maybe the series that has ShowInLegend = true has no values? That's the only explanation I can think for tmpSeries.CountLegendItems-FirstValue to be zero.
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

Errol
Newbie
Newbie
Posts: 14
Joined: Fri Jul 08, 2016 12:00 am

Re: After Hover, legend not shown with a single series

Post by Errol » Tue Mar 07, 2017 9:55 pm

Hi Yeray

Thanks for your reply. I can assure you that the series has values. I have attached 3 images showing the behaviour of the program before and after installing TeeChart 2015.15 in July 2015, using the same data. As you can see, the legend was displayed with a single series before TeeChart 2015.15, and not displayed after.
ChartWithTwoSeries_BeforeTeeChart2015_15.jpg
Chart with two series before TeeChart 2015.15
ChartWithTwoSeries_BeforeTeeChart2015_15.jpg (63.58 KiB) Viewed 19428 times
ChartWithOneSeries_BeforeTeeChart2015_15.jpg
Chart with one series before TeeChart 2015.15
ChartWithOneSeries_BeforeTeeChart2015_15.jpg (53.03 KiB) Viewed 19430 times
ChartWithOneSeries.jpg
Chart with one series after TeeChart 2015.15
ChartWithOneSeries.jpg (63.37 KiB) Viewed 19431 times
I do not understand why this legend error does not occur with a simple example, but it definitely occurs in our program, and the only change to the code has been the installation of TeeChart 2015.15. I notice that TeeChart sets the InternalLegendStyle to lsValues if ActiveSeriesInLegend = 1 (see code below). It appears that this change means that legend placement is different for a single series chart in some cases.

Code: Select all

Procedure TCustomChartLegend.CalcLegendStyle;

begin
  if FLegendStyle=lsAuto then
  begin
    if CheckBoxes or (ActiveSeriesInLegend>1) then
       InternalLegendStyle:=lsSeries
    else
       InternalLegendStyle:=lsValues;
  end
  else
    InternalLegendStyle:=FLegendStyle;
end;

This definitely seems to be a TeeChart error, although difficult to track down the cause. I look forward to any suggestions you may have.

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

Re: After Hover, legend not shown with a single series

Post by Yeray » Wed Mar 08, 2017 11:01 am

Hello,

I'm afraid it's difficult to guess without a simple application to reproduce the problem.
If you can debug the sources, both your application sources and TeeChart's, maybe you can find what conditions make the problem to appear.
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

Errol
Newbie
Newbie
Posts: 14
Joined: Fri Jul 08, 2016 12:00 am

Re: After Hover, legend not shown with a single series

Post by Errol » Wed Mar 08, 2017 9:15 pm

Hi Yeray

I believe I have worked out why TeeChart is failing to show a legend with a single series. You may remember that some time ago I requested an option to limit the number of points displayed in a series without changing the series. I have attached two images to show a typical series with all points displayed and only five points displayed.
ChartWithAllPointsDisplayed.jpg
ChartWithAllPointsDisplayed.jpg (107.52 KiB) Viewed 19417 times
ChartWithFivePointsDisplayed.jpg
Chart with only five points displayed per series
ChartWithFivePointsDisplayed.jpg (98.63 KiB) Viewed 19415 times
Because Steema have not yet offered this option, we have developed our own version which involves creating 3 series for each set of data, a Line Series, a Fast Line Series and a Point Series. The Fast Line Series and the Point Series are plotted on the graph but not shown in the legend. The line Series is used only for drawing the legend, and is not plotted on the graph. To achieve this functionality, I detached the Line Series from the data source using the following code.

Code: Select all

procedure TQSCollection.DetachLineSeriesDataSource;
var
  i{,iPos}: integer;

begin
  for i:=0 to SeriesListL.Count-1 do
    with TUnitLineSeries(SeriesListL.Objects[i]) do
      DataSource := nil;
end;
I suspect that this is the cause of the problem. There are no values in the series, but I still want to draw a legend, which used to happen in TeeChart 2014 but does not in 2015.15. I would appreciate it if you can suggest some workaround to solve this problem.

By the way, I would like to express my concern that Steema have not yet developed a LineSeries with control over the number of points displayed. This is absolutely necessary for effective display of data-dense scientific data, and it seems to me that Steema are not very serious about providing a good scientific graphing tool, but rather a business/presentation tool. I look forward to your comments.

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

Re: After Hover, legend not shown with a single series

Post by Yeray » Thu Mar 09, 2017 12:04 pm

Hello,
Errol wrote:Because Steema have not yet offered this option, we have developed our own version which involves creating 3 series for each set of data, a Line Series, a Fast Line Series and a Point Series. The Fast Line Series and the Point Series are plotted on the graph but not shown in the legend. The line Series is used only for drawing the legend, and is not plotted on the graph. To achieve this functionality, I detached the Line Series from the data source using the following code.
Probably the easier would be to try a different approach.
You could try to inherit TLineSeries adding the functionality to mark the points as VisiblePointer using an array of booleans or a similar approach.
I'm not sure if your data is being updated. In that case, the array should also been maintained accordingly.
Then, you could use OnGetPointerStyle event to show or hide the pointers. Ie:

Code: Select all

uses Series;

type
  TMyLineSeries = class(TLineSeries)
    public
      VisiblePointer: array of Boolean;
  end;

procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
begin
  Chart1.View3D:=False;
  Chart1.Legend.Alignment:=laBottom;

  for i := 0 to 2 do
    with Chart1.AddSeries(TMyLineSeries) as TMyLineSeries do
    begin
      Pointer.Visible:=True;
      Pointer.Size:=2;
      FillSampleValues(1000);

      SetLength(VisiblePointer,Count);
      for j:=0 to Count-1 do
        VisiblePointer[j]:=j mod 200=0;

      OnGetPointerStyle:=SeriesGetPointerStyle;
    end;
end;

function TForm1.SeriesGetPointerStyle(Sender:TChartSeries; ValueIndex:Integer):TSeriesPointerStyle;
begin
  result:=psNothing;
  if Sender is TMyLineSeries then
    with (Sender as TMyLineSeries) do
      if VisiblePointer[ValueIndex] then
        result:=Pointer.Style;
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

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

Re: After Hover, legend not shown with a single series

Post by Yeray » Thu Mar 09, 2017 12:32 pm

Hello again,
Yeray wrote:Then, you could use OnGetPointerStyle event to show or hide the pointers. Ie:
An alternative to OnGetPointerStyle would be to override DrawPointer method. Ie:

Code: Select all

  TSeriesPointerItemsAccess = class(TSeriesPointerItems);

//...

Procedure TMyLineSeries.DrawPointer(AX,AY:Integer; AColor:TColor; ValueIndex:Integer);
var tmpItem: TSeriesPointer;
begin
  tmpItem:=TSeriesPointerItemsAccess(Pointer).InternalGet(ValueIndex);
  tmpItem.Visible:=VisiblePointer[ValueIndex];

  inherited;

  tmpItem.Visible:=True;
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

Errol
Newbie
Newbie
Posts: 14
Joined: Fri Jul 08, 2016 12:00 am

Re: After Hover, legend not shown with a single series

Post by Errol » Thu Mar 09, 2017 8:30 pm

Hi Yeray

Thanks for your comments. I always thought that creating 3 series was not the best approach. However, to change the code as you suggest will require substantial changes to existing code, not least that involved in counting legends and series for hover highlighting, although overall the code is likely to be considerably simpler. In the short term, can you suggest a fix for the non-display of the legend where there is one legend item and the DataSource has been set to nil. This used to work before TeeChart 2015.15.

Thanks and regards

Errol

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

Re: After Hover, legend not shown with a single series

Post by Yeray » Fri Mar 10, 2017 10:00 am

Hi Errol,

I've just tried to reproduce the problem with this simple example:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
begin
  Chart1.View3D := False;
  Chart1.Legend.Alignment:=laBottom;

  For i:=0 To 2 do
  begin
    with Chart1.AddSeries(TFastLineSeries) do
    begin
      ShowInLegend:=False;
      FillSampleValues(100);
    end;
    with Chart1.AddSeries(TPointSeries) as TPointSeries do
    begin
      ShowInLegend:=False;
      Pointer.Size:=2;
      Color:=Chart1[Chart1.SeriesCount-2].Color;
      for j:=0 to 5 do
        if Chart1[Chart1.SeriesCount-2].Count>j*20 then
          AddXY(Chart1[Chart1.SeriesCount-2].XValue[j*20], Chart1[Chart1.SeriesCount-2].YValue[j*20]);
    end;
    with Chart1.AddSeries(TLineSeries) as TLineSeries do
    begin
      Pointer.Size:=2;
      Pointer.Visible:=True;
      Color:=Chart1[Chart1.SeriesCount-2].Color;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Chart1[2].Visible:=False;
  Chart1[5].Visible:=False;
end;
And I found the legend comes back if I force its LegendStyle to lsSeries:

Code: Select all

  Chart1.Legend.LegendStyle:=lsSeries;
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

Post Reply