Delphi Seattle, TChart Pro 2015.16
I need to create a custom legend. The chart only has one bar series, but negative values are displayed in red (additional lump savings needed for today) and represent a different value than positive value (cash balance at life expectancy).
How can I in code create a custom legend that shows 2 items, one with the series color and one with clRed color box, each with custom description/text. (I checked out the extended demo, but it gives me a "Control has no parent window" exception when I look at the New Chart Tools/Custom Legend Tool demo).
Thank you,
Ed Dressel
PS: I really don't like changing my login every year--I lose easy access to my previous posts. Sigh.
Creating a custom legend
Re: Creating a custom legend
Hello,
It could be it's easier than that. You can hide your TBarSeries from the legend and create two extra series without values but with color and title, just to be shown at the legend. Ie:
It could be it's easier than that. You can hide your TBarSeries from the legend and create two extra series without values but with color and title, just to be shown at the legend. Ie:
Code: Select all
uses Series;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
with Chart1.AddSeries(TBarSeries) as TBarSeries do
begin
for i:=0 to 5 do
if i mod 2 = 0 then
AddBar(50+random*50, '', clTeeColor)
else
AddBar(-50-random*50, '', clRed);
ShowInLegend:=false;
MultiBar:=mbNone;
end;
with Chart1.AddSeries(TBarSeries) as TBarSeries do
begin
Color:=Chart1[0].Color;
Title:='Positive';
end;
with Chart1.AddSeries(TBarSeries) as TBarSeries do
begin
Color:=clRed;
Title:='Negative';
end;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Creating a custom legend
Hi,
I want to do something similar, except that:
- I'm using a TLineSeries, so I need to keep all the points in one series so that they are drawn properly connected;
- Values are coloured according to some quality flag which affects only a few points in the series.
So I'd like to keep the default legend but add at run-time some custom lines, describing the quality flags, that include a coloured symbol and some text. Is this possible?
Thanks
Toreba
I want to do something similar, except that:
- I'm using a TLineSeries, so I need to keep all the points in one series so that they are drawn properly connected;
- Values are coloured according to some quality flag which affects only a few points in the series.
So I'd like to keep the default legend but add at run-time some custom lines, describing the quality flags, that include a coloured symbol and some text. Is this possible?
Thanks
Toreba
Re: Creating a custom legend
Hi Toreba,
The only difference is that you don't want to hide the original series from the legend.
If you still find any doubt about it, please don't hesitate to let us know.
The solution would be almost the same. You can add as many dummy series (series without values) as new items you want in the legend.Toreba wrote:So I'd like to keep the default legend but add at run-time some custom lines, describing the quality flags, that include a coloured symbol and some text. Is this possible?
The only difference is that you don't want to hide the original series from the legend.
If you still find any doubt about it, please don't hesitate to let us know.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Creating a custom legend
Hi Yeray,
Thanks for the suggestion. This would work well if we could prevent the dummy series from appearing in the list of series shown by TChartEditor. Is this possible?
Regards
Toreba
Thanks for the suggestion. This would work well if we could prevent the dummy series from appearing in the list of series shown by TChartEditor. Is this possible?
Regards
Toreba
Re: Creating a custom legend
Hi Toreba,
Yes, you can set a series ShowInEditor property to false.Toreba wrote:This would work well if we could prevent the dummy series from appearing in the list of series shown by TChartEditor. Is this possible?
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Creating a custom legend
Yeray,
Ah yes, so there is. That's excellent. Thank you very much for your help.
Regards
Toreba
Ah yes, so there is. That's excellent. Thank you very much for your help.
Regards
Toreba