Hello,
We produce graphics like in the attached plot with TChart, where we use a ColorGrid plus 3 Line Series.
Usually we display the Colors of the Color Grid in the Legend. Now we want in addition to show a legend for the 3 Line Series. But when we include the Line Series in the Legend the Color Grid colors are vanishing, see attachment.
How can we have the Color Grid colors Legend AND a Legend for the Line Series?
Thanks and best regards
How to get correct Legend for ColorGrid AND Line Series
How to get correct Legend for ColorGrid AND Line Series
- Attachments
-
- Legend1CaptureNew.png (404.6 KiB) Viewed 29768 times
-
- Legend2Capture.PNG (198.18 KiB) Viewed 29768 times
Re: How to get correct Legend for ColorGrid AND Line Series
Hello,
When the legend shows the palette, I don't see a lot of space to show any other item. Then, the ExtraLegendTool may be the most appropriate solution for this.
See the example here.
When the legend shows the palette, I don't see a lot of space to show any other item. Then, the ExtraLegendTool may be the most appropriate solution for this.
See the example here.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: How to get correct Legend for ColorGrid AND Line Series
Hello Yeray,
Thanks for the quick response, that indeed seems to be a way to proceed.
But how can I make sure to just just show the 3 Line Series in THAT extra legend?
Best regards,
Thomas
Thanks for the quick response, that indeed seems to be a way to proceed.
But how can I make sure to just just show the 3 Line Series in THAT extra legend?
Best regards,
Thomas
Re: How to get correct Legend for ColorGrid AND Line Series
To phrase this question differently, how can I explicitly decide in which of both (or more) Legends any Series is shown?
Because Series.ShowInLegend is global for all Legends.
Because Series.ShowInLegend is global for all Legends.
Re: How to get correct Legend for ColorGrid AND Line Series
Hello,
You could do something similar to the discussed here.
You could do something similar to the discussed here.
Code: Select all
uses TeEngine, Chart, Series, TeeSurfa, TeeExtraLegendTool;
type TMyExtraLegendTool=class(TExtraLegendTool)
protected
procedure ChartEvent(AEvent: TChartToolEvent); override;
end;
TLegendAccess=class(TChartLegend);
var Chart1: TChart;
procedure TMyExtraLegendTool.ChartEvent(AEvent: TChartToolEvent);
var i: Integer;
begin
if AEvent=cteAfterDraw then
begin
for i:=0 to ParentChart.SeriesCount-1 do
ParentChart[i].ShowInLegend:=ParentChart[i] is TLineSeries;
if Assigned(ParentChart) and Assigned(Series) then
begin
if Legend.Visible then
begin
TLegendAccess(Legend).CalcRect;
Legend.DrawLegend;
end;
end;
end;
end;
procedure TForm1.Chart1BeforeDrawChart(Sender: TObject);
var i: Integer;
begin
for i:=0 to Chart1.SeriesCount-1 do
Chart1[i].ShowInLegend:=Chart1[i] is TColorGridSeries;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1:=TChart.Create(Self);
with Chart1 do
begin
Parent:=Self;
Align:=alClient;
Color:=clWhite;
Gradient.Visible:=False;
Walls.Back.Color:=clWhite;
Walls.Back.Gradient.Visible:=False;
View3D:=False;
OnBeforeDrawChart:=Chart1BeforeDrawChart;
end;
with TColorGridSeries(Chart1.AddSeries(TColorGridSeries)) do
begin
Pen.Hide;
FillSampleValues;
end;
for i:=0 to 1 do
with TLineSeries(Chart1.AddSeries(TLineSeries)) do
begin
Pen.Width:=2;
FillSampleValues;
end;
Chart1.Draw;
with TMyExtraLegendTool(Chart1.Tools.Add(TMyExtraLegendTool)) do
begin
Series:=Chart1[1];
Legend.LegendStyle:=lsSeries;
Legend.Left:=Chart1.Legend.Left;
Legend.Top:=Chart1.ChartRect.Top;
end;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: How to get correct Legend for ColorGrid AND Line Series
Thanks a lot, we are practically there:
I am setting the Position in the Create of the form but it looks like I need to update the position of the
extra legend before the painting.
One other quick question, how can I change/influence the texts that are shown in the Extra legend, I'd like to have other text than names of the Series?
I am setting the Position in the Create of the form but it looks like I need to update the position of the
extra legend before the painting.
One other quick question, how can I change/influence the texts that are shown in the Extra legend, I'd like to have other text than names of the Series?
Re: How to get correct Legend for ColorGrid AND Line Series
Hello,
You'd have one extra series for each entry you want to show in the legend. You can set their
Knowing their indexes, you could modify the code in the
Yes, that's why I called
Draw
before creating the TExtraLegendTool
at OnCreate
in the example above.We use to recommend adding extra dummy series to be shown in the legend.
You'd have one extra series for each entry you want to show in the legend. You can set their
Color
property to match the colors of the main series, setting your custom Title
to them, but without adding any data to them.Knowing their indexes, you could modify the code in the
TMyExtraLegendTool.ChartEvent
to only activate ShowInLegend
property for those dummy series.Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: How to get correct Legend for ColorGrid AND Line Series
Ok, I just had to populate the Title properties of the Line Series, all perfect now, thanks!