Page 1 of 1

Extra legend

Posted: Wed Aug 01, 2012 1:25 am
by 10546565
This is my last item before I finish my app update, so I am a bit pressed to get this out.

XE2. TChart 2012.06

I am adding an extra legend via code to my chart. I want it to only have two items with custom text (unrelated to the series--they are categories of series, not series in themselves). Also, I need it to show below the current legend. I.e.

Image

It would be nice if the symbols and text were vertically aligned, but I need some margin between the two legends.

Is this possible? I have attached my demo program that produces the sample image. What needs to change?

Much appreciated,

Ed Dressel

Re: Extra legend

Posted: Wed Aug 01, 2012 9:15 am
by yeray
Hi Ed,

The TExtraLegendTool is probably too much linked to the regular series than what you'd need. Ie, the ShowInLegend property is shared with both legends so the only way to have a different number of items in both legends is linking a series to the TExtraLegendTool. You could create a dummy series for it, with as many values as number of items to show (and the series.Active:=false for not drawing it)

Alternatively, you could use the more flexible TCustomLegendTool. Take a look at the example at "What's New ?\Welcome !\New Chart Tools\Custom Legend" in the features demo.

In both cases you'll have to calculate the legend position manually. I'd suggest you to take a look at the "Extra Legend tool" example in the features demo. Find it at "All features\Welcome !\Tools".

Re: Extra legend

Posted: Wed Aug 01, 2012 2:25 pm
by 10546565
Thank you... I am very close now. I created the dummy series and have it positioned where I want it--but the legend insists on showing the value. Here is a image:

Image

I added Null to the series values, but it still shows. I looked at the source code and couldn't figure it out.

I have attached the modified demo.

How can the value be removed?

(I looked at the Custom Legend demo, but when I try to view the Form, I get an "Invalid stream format" exception).

Thank you,

Ed Dressel

Re: Extra legend

Posted: Thu Aug 02, 2012 11:50 am
by yeray
Hi Ed,

I see in your project you've set:

Code: Select all

FExtraLegend.Legend.TextStyle:=ltsPlain;
However, it seems the Chart Legend TextStyle is checked instead in the sources. So this seems to work as you expected:

Code: Select all

Chart1.Legend.TextStyle:=ltsPlain;
We'll investigate why the Chart Legend TextStyle is taken instead of the ExtraLegend's.