Lazarus

Programming => General => Topic started by: AL on April 06, 2020, 06:34:26 pm

Title: Anchor question
Post by: AL on April 06, 2020, 06:34:26 pm
If I have a chart on a form, anchoring all sides to the form will make the chart expand as I expand the form. That is simple.

If I have 2 charts or even better 3 charts stacked vertically on a form.  How do I set the anchors so that when I expand the form, all charts expand proportionnally.
For the x axis this is simple, anchor both sides of the charts to the form sides.
But for the height ( Y axis) I have been playing with all kinds fo combinations for the last hours and cannot find one that does what I want.
Is this possible?
Thanks
Title: Re: Anchor question
Post by: wp on April 06, 2020, 06:52:48 pm
Will the stacked charts have the same size?
Title: Re: Anchor question
Post by: AL on April 06, 2020, 09:05:23 pm
Yes same size
In fact I have 5 all together.
Title: Re: Anchor question
Post by: wp on April 06, 2020, 10:00:03 pm
Then it's easy:
This results in equally sized charts. Use the LeftRightSpacing/TopLeftSpacing properties to add an additional margin at the outer sides and VerticalSpacing between the charts.

I thought that there is a way also to scale the charts in proportion to their original size, but don't get it to work ATM...
Title: Re: Anchor question
Post by: AL on April 06, 2020, 10:42:19 pm
OK thank you.  I have not used panels until now, but I see it seems a good practice to put a panel in the form.

So there is no solution with anchors only. This makes me feel less dumb  :D
Title: Re: Anchor question
Post by: jamie on April 06, 2020, 11:33:09 pm
Would the TFLowPanel be a good control for this ?
Title: Re: Anchor question
Post by: wp on April 07, 2020, 12:06:01 am
Here is another solution in which you can freely change the size of the individual charts, even at runtime:
Of course you can extend this to four, five, any number of charts.
Title: Re: Anchor question
Post by: AL on April 08, 2020, 12:34:01 am
2 good options.
I have implemented the panel option, works very well.  Thank you.

I have added a charttoolset.(One set for all charts)  When I use the distance tool the measure is displayed in the last chart I clicked in.  The distance tool is using right-click.
So if I measure a distance in the chart 1 it works Ok
Then I go to chart 2 and the distance is still displayed in chart 1.
If I click in the chart2 first before measuring then is measuring correctly.
I think it is more a problem of focus than a problem with the tool.
All charts have autofocus property set to true.
Any suggestions?
Title: Re: Anchor question
Post by: wp on April 08, 2020, 01:28:08 am
Look at the source code of TBasicChartTool (unit TAGraph) which is the most fundamental chart tool:
Code: Pascal  [Select][+][-]
  1. type
  2.   TBasicChartTool = class(TIndexedComponent)
  3.   strict protected
  4.     FChart: TChart;
  5.      ...
  6.   public
  7.     property Chart: TChart read FChart;
  8.   end;
There is a property Chart which tells on which chart the tool operates. This is set when the ToolSet is assigned to the chart. For this reason a tool does not work with a second chart, and you cannot share the same toolset with two charts. Therefore, you simply copy the current toolset to the clipboard and paste it back into the form. Then make sure that the second chart uses the second toolset.
Title: Re: Anchor question
Post by: AL on April 08, 2020, 02:07:41 am
OK. but strangely, the zoom and pan tools from the toolset works in all charts.
No problem I will make one toolset per chart.
Thank you
Title: Re: Anchor question
Post by: wp on April 08, 2020, 03:17:37 pm
OK. but strangely, the zoom and pan tools from the toolset works in all charts.
It is the same issue, with a bit different behaviour though. When I add ONE ZoomDragTool to a form with two charts and assign it to BOTH charts and drag the zoom rect in the chart which was assigned last then the zoom rect is drawn in the other chart but the zoom occurs in the same chart. Quite crazy!

Yes, without an extra zoomdrag tool the behavior is correct because every chart has a built-in toolset with zoomdrag and pandrag tools. so, we have the situation like when you added two separate toolsets.
TinyPortal © 2005-2018