Michael Meier
Michael Meier

Reputation: 21

Teechart TChart Legend - increase count of items

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

Upvotes: 2

Views: 1433

Answers (2)

pyfyc
pyfyc

Reputation: 157

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.

Upvotes: 0

Michael Meier
Michael Meier

Reputation: 21

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

Upvotes: 0

Related Questions