Question

I have a TChart (Steema TeeChart included in Delphi IDE) component which may have up to 64 Chart Series (Stacked Area in my case). I need to display all existent series in chart, but Legend, unfortunately, doesn't show all of existing series, only some firsts of them 10-16 (see picture). Chart with 64 series

Is it possible somehow to Scroll Legend for viewing all existing series? If not directly maybe some workaround?

used Delphi7, Chart v4

Was it helpful?

Solution

Here is my own implementation, based on TChart.OnMouseWheel event, simulating Legend scrolling (it is scrolled, but without any scroll bar - maybe it will be task for future):

procedure TForm1.Chart1MouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);

  function GetChartActiveSeriesCount(aChart: TChart): Integer;
  var
    iIdx: Integer;
  begin
    Result := 0;
    for iIdx := 0 to aChart.SeriesCount-1 do
    begin
      if aChart.Series[iIdx].Active = True then
        Inc(Result);
    end;
  end;

var
  lCliMousePos: TPoint;
  lActiveCount: Integer;
  lChart: TChart;
begin
  lChart := TChart(Sender);
  lCliMousePos := lChart.ScreenToClient(MousePos);
  if PtInRect(lChart.Legend.RectLegend, lCliMousePos) then
  begin
    if WheelDelta > 0 then
    begin
      if lChart.Legend.FirstValue > 0 then
        lChart.Legend.FirstValue := lChart.Legend.FirstValue-1;
    end
    else
    begin
      lActiveCount := GetChartActiveSeriesCount(lChart);
      if (lChart.Legend.FirstValue + lChart.Legend.NumRows) < lActiveCount then
      lChart.Legend.FirstValue := lChart.Legend.FirstValue+1;
    end;
  end;
  Handled := True;
end;

Also there are some tricks how to trigger TChart.OnMouseWheel event, because Tchart cannot get focus it is needed to play with Main Form OnMouseWheel event or WM_MOUSEWHEEL windows message. HowTos here: http://delphi.about.com/od/delphitips2010/qt/delphi-redirect-mouse-wheel-control-under-the-mouse.htm or here: http://delphi.about.com/od/delphitips2010/qt/timage-handling-mouse-wheel-messages.htm

OTHER TIPS

This is only possible with the Professional edition of TeeChart. It includes the Legend ScrollBar tool (TLegendScrollBar) for this purpose. Fully functional evaluation versions can be downloaded here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top