Aligning multiple charts

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Aligning multiple charts

Post by Metman » Wed Aug 29, 2012 1:50 pm

Hi

I want to stack six charts vertically on top of each other. All the charts are for the same period and I have added a vertical chart tool to each chart to show the selected time. This works fine but the labels on the left axis are always a slightly different width so I can't alight the left wall of each chart. I have tried setting the panel width both by pixel and percentage but with no luck can anyone give me a clue?

The other thing I would like to is disable the labels from the 'inner' four charts but still show the grid. This too seems impossible - all I want to do is show the grid without either the bottom or top labels.

Bruce

Here is a screenshot:
Attachments
Capture1.png
Capture1.png (34.11 KiB) Viewed 9985 times

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Aligning multiple charts

Post by Yeray » Wed Aug 29, 2012 2:15 pm

Hi Bruce,

Give a look at the discussion that took place here:
http://www.teechart.net/support/viewtop ... rts#p53188
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Re: Aligning multiple charts

Post by Metman » Wed Aug 29, 2012 2:31 pm

Yeray

I'll have a look at the topic and see if I can make it work - what about the second question though having (vertical) grid lines without having the corresponding labels visible?

Bruce.

Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Re: Aligning multiple charts

Post by Metman » Wed Aug 29, 2012 2:55 pm

Yeray

The label size property worked a treat. Still would like to disable the labels without disabling the grid though. Any thoughts???

Bruce.

Capture2.png
Capture2.png (38.26 KiB) Viewed 9991 times

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Aligning multiple charts

Post by Yeray » Thu Aug 30, 2012 8:55 am

Hi Bruce,

To hide the labels, still showing the grid, you could use the OnGetAxisLabel event to assign an empty string to the desired labels.
Here it is a .NET example, but the same applies to VCL.
If you find any problem with it, don't hesitate to let us know.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Re: Aligning multiple charts

Post by Metman » Sun Sep 02, 2012 4:37 pm

Yeray

Thanks for the link - I had a try at some of these work arounds and none of them work very satisfactorily.

I tried keeping the labels and using the same colored font for the test as the background. This works OK put appears on printing. Tried your suggestion of taking over the label drawing and painting nothing to the screen - the grid disappeared. I found you need to add a single space to get the grid back. Tried setting the label on axis to false which does help but why I don't know.

I thought the grid spacing was controlled by the amount and size of the text that makes up the label but now I'm not so sure. What I would like is grid and label separating so you can turn labels off and leave grid on.

I can't get the 6 graph I have stacked on top of each other to scale the grid exactly the same despite having the increments top and bottom the same. I'll keep working at it but the whole area needs reworking in my opinion and is a complete minefield!

Bruce.
Attachments
Capture1.png
Capture1.png (81.01 KiB) Viewed 9932 times

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Aligning multiple charts

Post by Yeray » Tue Sep 04, 2012 10:05 am

Hi Bruce,

I'm trying to reproduce it but I can't. Here you have the simple example project I'm using:

Code: Select all

var Chart1, Chart2: TChart;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1:=TChart.Create(Self);
  Chart1.Parent:=Self;
  Chart1.Align:=alTop;

  Chart2:=TChart.Create(Self);
  Chart2.Parent:=Self;
  Chart2.Align:=alTop;

  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;
  Chart2.View3D:=false;
  Chart2.Legend.Visible:=false;

  Chart1.AddSeries(TFastLineSeries).FillSampleValues(100);
  Chart2.AddSeries(TBarSeries).FillSampleValues(100);
  Chart2[0].Marks.Visible:=false;

  Chart2.MarginBottom:=1;
  Chart2.Axes.Bottom.OnDrawLabel:=Chart1AxisDrawLabel;
  Chart2.Axes.Bottom.Ticks.Visible:=false;
  Chart2.Axes.Bottom.MinorTicks.Visible:=false;

  LeftAlignCharts([Chart1,Chart2],100,600);

  Chart1.Axes.Bottom.MinimumOffset:=5;
  Chart1.Axes.Bottom.MaximumOffset:=5;
  Chart2.Axes.Bottom.MinimumOffset:=5;
  Chart2.Axes.Bottom.MaximumOffset:=5;
end;

procedure TForm1.Chart1AxisDrawLabel(Sender:TChartAxis; var X,Y,Z:Integer;
                   var Text:String; var DrawLabel:Boolean);
begin
  if Sender = Chart2.Axes.Bottom then
    Text:=' ';
end;

procedure TForm1.LeftAlignCharts(Const Charts: Array of TCustomChart; aLeft: Integer; aWidth: Integer);
var i: Integer;
begin
  for i := Low(Charts) to High(Charts) do
  With Charts[i] do
  begin
    Left := aLeft;
    MarginLeft := 0;
    Width := aWidth;
    Axes.Left.TitleSize := 15;
    Axes.Left.LabelsSize := 30;
    Axes.Left.LabelsAlign := alDefault;
  end;
end;
The only problem I've found is that the TBarSeries applies an internal offset to the bottom axis minimum&maximum so the first and last bars can be completely shown. However, having the same number of values in both charts, the axis minimum, maximum and increment are automatically the same, so I don't need to manually set them.

If you still have problems with it, please try to modify the code above so we can reproduce the situation here.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply