2

enter image description here

I have a TDBChart and it shows a legend, about 25 lines or so. How can I increase the item count which are shown in the legend? In other words: I want the legend to have more lines than it has now.

OPTIMAL would be, if the line count would be exactly filling the height of the chart. I am aware, that this must take into consideration which font is chosen.

Thanks

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • It's happening with my TeeChart v8.03.11068 (and it's pretty old version). Number of legend rows grows as I resize the chart control. There is the `Legend.MaxNumRows` property, but it's used only for legend placed on top or bottom of the chart (not for left and right placement). – Victoria Oct 27 '17 at 15:44
  • thank you for the hint.
    I (Teechart 12 or so, should not matter) tried: DBChart1.Legend.MaxNumRows:=100;
    and
    DBChart1.Legend.NumRows:=100;
    Unfortunately it does not change anything. I see only 16 lines. Maybe I blocked the line-increase by any other setting, but which?
    – Michael Meier Oct 27 '17 at 16:08
  • So you placed the legend on top or bottom? And what is the legend's `LegendStyle`? P.S. version might be important. – Victoria Oct 27 '17 at 16:22
  • an image says more than 1000 words, let me check, how to add it // click the very first word of my very first posting pls – Michael Meier Oct 28 '17 at 11:01
  • Isn't the idea of a legend to have a list of explanations of the colors/shapes, rather than the actual values? – GolezTrol Oct 28 '17 at 12:00
  • Michael, I understood your problem. I cannot reproduce it. The legend is resized automatically for me. Could you include *.dfm configuration of your chart object, please? It can be `FirstValue`, or something else (I just don't want to guess anymore). – Victoria Oct 28 '17 at 14:32

2 Answers2

0

I am not sure, if the answer is true, because Steema mixes sometimes runtime and designtime and saves one into the other. Something changed in my source and it works for me now. Most probably solution comes here:

All hints like this may work in theory:
DBChart1.Legend.Items.Capacity:=100;
DBChart1.Legend.MaxNumRows:=100;
DBChar1.Legend.NumRows:=100;

BUT, everything is overwritten by the automatic legend. So the first thing, which has to be done is: set it to custom! You do it like this:
DBChart1.Legend.Items.Custom:=true;

I found the solution in the documentation of Steema:
http://www.teechart.net/docs/teechart/net/lib/index2.htm

  • Have you managed to make it work for you? As far as I researched the MaxNumRows property works only when the legend is placed on Top or Bottom. But in my case it is on the Right. The same as in your case as I understand. – pyfyc Sep 14 '22 at 10:51
0

I found a solution for the case when the legend is on the Left/Right position. Legend has FirstValue property. So you can implement a kind of multiple pages legend. You can add a button and add this code for the OnClick event:

  if peLineGraph.Legend.FirstValue = 0 then
  begin
    peLineGraph.Legend.FirstValue := peLineGraph.Legend.Items.Count;
    btnShowMoreSeries.Caption := SHOW_FIRST_SERIES;
  end
  else begin
    peLineGraph.Legend.FirstValue := 0;
    btnShowMoreSeries.Caption := SHOW_NEXT_SERIES;
  end;

Where peLineGraph is TChart and btnShowMoreSeries is your new button on the chart. My code is for the case when there are only two pages in the legend. But you can also implement more pages if you need to.

Sure you don't want the btnShowMoreSeries button to show up there every time. You will need it only when the number of actual series is more than the number fit in the legend. That you can easily check in the peLineGraphAfterDraw event. You can also adjust the left position of your button there:

  if btnShowMoreSeries.Visible = False then
  begin
    if (Sender as TChart).SeriesCount > (Sender as TChart).Legend.Items.Count then
    begin
      btnShowMoreSeries.Caption := SHOW_NEXT_SERIES;
      btnShowMoreSeries.Visible := True;
    end;
  end;
  btnShowMoreSeries.Left := (Sender as TChart).Legend.Left;

Initially btnShowMoreSeries.Visible can be False. And you need to set it to False every time when you generate a new chart.

pyfyc
  • 127
  • 2
  • 9