Page 1 of 1

How to build more than one legend on the same dbchart

Posted: Tue Dec 12, 2006 1:32 am
by 9348298
Hi

I have two problem ( delphi7 and TeeChart7.07):
1. How to build more than one legend on the same dbhart ,and can move the legend to anywhere on the dbchart according to custom needs run time, becuse I have four groups series on the dbchart, every group series include about 10 LineSeries, and want to arrange the four groups series on four different legend.

2. When I link dbchart LineSeries to a sql table ,why do not change the dbchart bottomaxis Increment property to "Increment:=DateTimeStep[dtOneYear]" runtime?

I have the picture of the Result runtime,but I do not know how to send here.

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, TeEngine, Series, StdCtrls, ExtCtrls, TeeProcs,
  Chart, DBChart;

type
  TForm1 = class(TForm)
    DBChart1: TDBChart;
    ADOQuery1: TADOQuery;
    Button1: TButton;
    Series1: TLineSeries;
    ADOConnection1: TADOConnection;
    Chart1: TChart;
    ADOQuery2: TADOQuery;
    Series2: TLineSeries;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
  uses math;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var dd:TDatetime;
y:double;
begin
  ADOQuery1.Close;
  ADOQuery1.SQL.Text:='select ValDate,e from tb_0001 order by ValDate';
  series1.XLabelsSource:='ValDate';
  series1.YValues.ValueSource:='e';
  series1.Clear;
  ADOQuery1.Open;
  DBChart1.BottomAxis.Increment:=DateTimeStep[dtOneYear];
  DBChart1.BottomAxis.MinorTickCount:=11;
  DBChart1.BottomAxis.DateTimeFormat:='YYYY';
  ADOQuery2.Close;
  ADOQuery2.SQL.Text:='select ValDate,sigma from tb_0002 order by ValDate';

  ADOQuery2.Open;
  Series2.Clear;
  while not ADOQuery2.Eof do
  begin
    dd:=ADOQuery2.Fields[0].AsDateTime;
    y:=ADOQuery2.Fields[1].Value;
    Series2.AddXY(dd,y);
    ADOQuery2.next;
  end;
  Chart1.BottomAxis.Increment:=DateTimeStep[dtOneYear];
  Chart1.BottomAxis.MinorTickCount:=11;
  Chart1.BottomAxis.DateTimeFormat:='YYYY';
end;

end.

Posted: Tue Dec 12, 2006 2:59 pm
by narcis
Hi hexfhhu,

1. Please see Pep's reply at your other thread.

2. Axes will be scaled according to the given increment provided the requested label scaling fits on the axis. Otherwise labels increment automatically increases to fit in the axis.

Anyway, you can try forcing that using:

Code: Select all

  Chart1.Axes.Bottom.LabelsSeparation:=0; 
Setting LabelsSeparation to zero is the extrem case to force as many labels as possible being drawn. You can try "playing" a little bit with this property setting it to small values that produce the labels as you expect.