Page 1 of 1

synchronization of two opposite axis

Posted: Wed Mar 04, 2020 5:55 pm
by 16588166
Hello :) ,
First and second of my three problems are shown in the chart joined :
Firstable I need to explain that I fill series as follow :

Code: Select all

Series[0].AddXY(Occurs_No, y, FloatToStrF(Value_Of_x), ffNumber, 7, 2));
because I want to display the record number on BottomAxis, and the value of this record right in front, on TopAxis.

My first problem is that, Doing so, I'm not able to align the two values correctly on the grid, "face to face".
And my second problem is that, as you can see on the chart, when my data source returns only one record, the BottomAxis value is not shown in the middle of the axis, as my dreams would like.
I think the two problems are linked...

Could some one tell me how to resolve my problems, please :? ?

Re: synchronization of two opposite axis

Posted: Thu Mar 05, 2020 8:41 am
by yeray
Hello,

We'd need a simple example project we can run as-is to reproduce the problem here because I see no problems trying to achieve what I'm understanding you described:
Project1_2020-03-05_09-40-41.png
Project1_2020-03-05_09-40-41.png (9.51 KiB) Viewed 2425 times
Project1_2020-03-05_09-40-45.png
Project1_2020-03-05_09-40-45.png (17.32 KiB) Viewed 2425 times

Code: Select all

uses Series;

procedure TForm1.PopulateSeries(ACount: Integer);
var i: Integer;
begin
  Chart1[0].Clear;
  for i:=0 to ACount-1 do
    Chart1[0].AddXY(i,(i+1*10),'Value of ' + IntToStr(i));
end;

procedure TForm1.BMultipleValuesClick(Sender: TObject);
begin
  PopulateSeries(10);
end;

procedure TForm1.BSingleValueClick(Sender: TObject);
begin
  PopulateSeries(1);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart1.Legend.Hide;

  Chart1.Axes.Top.LabelStyle:=talText;
  Chart1.Axes.Bottom.LabelStyle:=talValue;

  with TBarSeries(Chart1.AddSeries(TBarSeries)) do
  begin
    ColorEachPoint:=True;
    HorizAxis:=aBothHorizAxis;
    Marks.Hide;
  end;
end;

Re: synchronization of two opposite axis

Posted: Thu Mar 05, 2020 9:47 am
by 16588166
Hello Yeray,
It's close to that. But the value I want to display on top axis is not the value of "i", but the value contained in the record number "i" :
DataSource :
1: 1250,30
2: 1360,60
3: 1610,14

Writing this, I realize that top axis must be out of sync from bottom axis. Sorry :?
I'd just like to display
1, 2, 3
on bottom axis and in front of each of these values, on the top axis
1250,30
1360,60
1610,14

Thanks for your help.

Re: synchronization of two opposite axis

Posted: Thu Mar 05, 2020 10:19 am
by 16588166
...and when I define TopAxis.Automatic at False,
it don't show anything anymore :( .

Re: synchronization of two opposite axis

Posted: Thu Mar 05, 2020 12:50 pm
by yeray
Hello,

I'm using an array to store the values to be displayed on the top but using a datasource should also work:

Code: Select all

var topValues: array of double = [1250.30, 1360.60, 1610.14];

procedure TForm1.PopulateSeries(ACount: Integer);
var i: Integer;
begin
  FormatSettings.DecimalSeparator:=',';
  FormatSettings.ThousandSeparator:='.';

  Chart1[0].Clear;
  for i:=0 to ACount-1 do
    with Chart1[0] do
    if i<Length(topValues) then
       AddXY(i,(i+1*10),FormatFloat('#,##0.##',topValues[i]))
    else
       AddXY(i,(i+1*10));
end;
Project1_2020-03-05_13-48-08.png
Project1_2020-03-05_13-48-08.png (17.34 KiB) Viewed 2415 times
odaumas wrote:
Thu Mar 05, 2020 10:19 am
...and when I define TopAxis.Automatic at False,
it don't show anything anymore :( .
You need to set the axis minimum and maximum values when you don't want it to be automatic.

Re: synchronization of two opposite axis

Posted: Thu Mar 05, 2020 1:00 pm
by 16588166
Ah ok, thanks.

Re: synchronization of two opposite axis

Posted: Thu Mar 05, 2020 4:04 pm
by 16588166
I do a clear chart, before creating the series dynamically.
Maybe I not define something correctly. :roll:

Re: synchronization of two opposite axis

Posted: Fri Mar 06, 2020 8:01 am
by yeray
Hello,

If you still find problems with it, please try to arrange a simple example project we can run as-is to reproduce the problem here.