Page 1 of 1
MaxLabelsWidth returns wrong value
Posted: Mon Jul 02, 2007 12:27 pm
by 9349911
Hi !
I have 6 series which use all the left axis.
Now I use this code to assign a customaxis to each serie.
Code: Select all
for Nr := 0 to Chart1.SeriesCount - 1 do begin
Chart1[Nr].CustomVertAxis := Chart1.CustomAxes.Items[Nr];
Chart1.CustomAxes.Items[Nr].Visible := True;
end;
If I use Chart1.Series[Nr].GetVertAxis.MaxLabelsWidth I got 9 as result. All maximum values from the axis are 0.
How can I recalculate the corrent axis values so that MaxLabelsWidth works correct?
Posted: Mon Jul 02, 2007 1:11 pm
by narcis
Hi Dominik,
This works fine for me here doing something like this:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
for i:=0 to Chart1.SeriesCount-1 do
begin
Chart1[i].FillSampleValues();
Chart1[i].CustomVertAxis:=Chart1.CustomAxes[i];
end;
Chart1.MarginLeft:=5;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
for i:=0 to Chart1.SeriesCount-1 do
Chart1.Title.Text.add(IntToStr(Chart1[i].GetVertAxis.MaxLabelsWidth));
end;
If this doesn't help please send us a simple example project we can run "as-is" to reproduce the problem here.
Thanks in advance.
Posted: Mon Jul 02, 2007 1:37 pm
by 9349911
Hi Narcis,
I´ve uploaded a file to the server:
Received Axis Demo 2.zip Content Type application/x-zip-compressed Length 27787
Here are the steps for reproducing :
1) Check "START"
2) After some seconds Uncheck "START"
3) Use Change VIEW -> "one Y-Axis for all Series"
4) Use Change VIEW -> "one Y-Axis per Series"
If you step through procedure TForm1.PlaceLVAxis; during step 4) you can see that Achse.MaxLabelsWidth is 9. This is because the maximum value of each axis is 0.
So what can I do ?
Posted: Mon Jul 02, 2007 2:27 pm
by narcis
Hi Dominik,
Thanks for the example but I don't see what effect does it make to your project. You may want to try calling Chart1.Draw so axes are properly drawn or ca.AdjustMaxMin. It this doesn't help please give us some more information about the exact problem.
Thanks in advance.
Posted: Mon Jul 02, 2007 5:56 pm
by 9349911
Hi Narcis,
That´s what I´m searching for.
Thx alot !
Posted: Mon Jul 02, 2007 7:05 pm
by 9349911
Hi Narcís,
there is one problem left. Hopefully you can give me a tip.
I uploaded a new and smaller demo application to your server:
Received Axis Demo 2_2.zip Content Type application/x-zip-compressed Length 20238
I have upload 2 pics to my server to show you my problem:
Pic1)
Pic2)
As you can see in the pics the axis values are overlapping. And I have no idea what causes this. I use a sample code from you which draws multiple Y-axis to the chart.
I have enhanced this code so that it alwas calculate the correct width for each y-axis.
This works really fine but if I add the first and the second point to each series I got this problem.
During the PlaceAxis I use the methode you mentioned above : Chart1[Nr].CustomVertAxis.
AdjustMaxMin;
As I said bevor ... It works really great after the third point was added.
Can you give me a tipp what causes this problem ?
Posted: Wed Jul 04, 2007 8:44 am
by yeray
Hi Dominik,
The problem is that for few number of values, axis labels are displayed with 3 decimals and when they display more values, their auto-rescaling makes them to display less decimals.
I suggest you to add an if condition to your code that evaluates the number of points in your series and if there are less than 3, use a higher "extraPos".
I hope it helps.
Posted: Wed Jul 04, 2007 8:48 am
by 9349911
Hi Yeray,
I suggest you to add an if condition to your code that evaluates the number of points in your series and if there are less than 3, use a higher "extraPos".
That´s exactly what I did in the meantime:
Code: Select all
Achsbreite := Achse.MaxLabelsWidth + Achse.TickLength;
If Achsbreite <= 13 then Achsbreite := 20;
This works ok for me.
Thx for your help !