Creating a custom legend

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Test Always
Newbie
Newbie
Posts: 14
Joined: Mon Jan 18, 2016 12:00 am

Creating a custom legend

Post by Test Always » Thu Jun 02, 2016 7:39 pm

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.

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

Re: Creating a custom legend

Post by Yeray » Fri Jun 03, 2016 11:09 am

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:

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,
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

Toreba
Newbie
Newbie
Posts: 29
Joined: Wed Sep 02, 2015 12:00 am

Re: Creating a custom legend

Post by Toreba » Thu Jun 30, 2016 5:00 pm

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

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

Re: Creating a custom legend

Post by Yeray » Mon Jul 04, 2016 7:29 am

Hi Toreba,
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 solution would be almost the same. You can add as many dummy series (series without values) as new items you want in the legend.
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,
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

Toreba
Newbie
Newbie
Posts: 29
Joined: Wed Sep 02, 2015 12:00 am

Re: Creating a custom legend

Post by Toreba » Mon Jul 04, 2016 8:37 am

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

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

Re: Creating a custom legend

Post by Yeray » Mon Jul 04, 2016 9:40 am

Hi Toreba,
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?
Yes, you can set a series ShowInEditor property to false.
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

Toreba
Newbie
Newbie
Posts: 29
Joined: Wed Sep 02, 2015 12:00 am

Re: Creating a custom legend

Post by Toreba » Mon Jul 04, 2016 11:43 am

Yeray,

Ah yes, so there is. That's excellent. Thank you very much for your help.

Regards

Toreba

Post Reply