After Hover, legend not shown with a single series
After Hover, legend not shown with a single series
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
I look forward to your comments
Regards
Errol
Re: After Hover, legend not shown with a single series
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:
Could you please arrange a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.
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;
Thanks in advance.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: After Hover, legend not shown with a single series
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
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
Re: After Hover, legend not shown with a single series
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
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.
Re: After Hover, legend not shown with a single series
Hi Errol,
I can't reproduce the problem.
Are you using the latest version available v2016.19?
I can't reproduce the problem.
Are you using the latest version available v2016.19?
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: After Hover, legend not shown with a single series
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.
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.
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
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)
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 look forward to your reply.
Best regards
Errol
Re: After Hover, legend not shown with a single series
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.
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: After Hover, legend not shown with a single series
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. 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.
This definitely seems to be a TeeChart error, although difficult to track down the cause. I look forward to any suggestions you may have.
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. 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;
Re: After Hover, legend not shown with a single series
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.
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: After Hover, legend not shown with a single series
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. 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.
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.
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. 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;
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.
Re: After Hover, legend not shown with a single series
Hello,
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:
Probably the easier would be to try a different approach.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.
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: After Hover, legend not shown with a single series
Hello again,
An alternative to OnGetPointerStyle would be to override DrawPointer method. Ie:Yeray wrote:Then, you could use OnGetPointerStyle event to show or hide the pointers. 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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: After Hover, legend not shown with a single series
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
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
Re: After Hover, legend not shown with a single series
Hi Errol,
I've just tried to reproduce the problem with this simple example:
And I found the legend comes back if I force its LegendStyle to lsSeries:
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;
Code: Select all
Chart1.Legend.LegendStyle:=lsSeries;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |