Recent

Author Topic: TAchart: Multiple Axes  (Read 15540 times)

wp

  • Hero Member
  • *****
  • Posts: 13628
TAchart: Multiple Axes
« on: March 03, 2012, 04:54:37 pm »
Several quantities (such as "Time", "Pressures", "Power", "Flow Rate") are combined as elements in a class and are stored in a List. I want to plot pressure, power and/or flow Rate as a function of time. Since these quantities have different units and different scales I decided to assign each of them to a separate axis. A ChartListbox is used to activate the individual series along with the corresponding axis.

When you run the attached demo and add the "power" series to the chart by clicking its checkmark in the listbox, you will see that both axes will have the same scale. I'd have expected that both axes will have different scaling such that each series fills the chart -- that's why I am using different axes at all.

Similarly, when you select the "Pressure logarithmic" checkbox, the pressure will be plotted on a log scale, but will be compressed only in the lower part of the chart. Obviously the log scale is affected by the range of the other axes.

Each axis should be independent of the others. Is that possible with TAChart?

Another question: Is there a way to increase the spacing between the title of one axis and the vertical line and tick marks of the next axis?

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TAchart: Multiple Axes
« Reply #1 on: March 03, 2012, 05:43:18 pm »
Quote
Each axis should be independent of the others. Is that possible with TAChart?

Yes, but slightly more complicated. See attached fixes to your demo
and http://wiki.lazarus.freepascal.org/TAChart_documentation#Auto-scaling_transformation

Basically, all axis ranges are projected onto a common graph space.
Their graph coordinates are determined by the transformations.
Chart extent is then calculated as the common
bounding box for all axises and series.

Thus, to create "independently scaled" axises a transformation is required
that would project any range of actual values into a fixed interval.
Such transformation exists and is named "AutoScaleTransform".

As usual, additional complexity is (hopefully) payed off by additional
power: in this case, you can control the interplay between
automatic scaling and other transformations (logarithm in your example).
Additionally, by changing MinValue and MaxValue property of
AutoScaleTransform, you can control the location of your auto-scaled series
inside the chart, and create different kinds of "paned" or
"oscilloscope-like" views.
See "Group flow and power" checkbox in the attached demo.

Note that axis grouping is used to support this feature (Axis.Group property).
While demonstrating it, I have found a bug/missing feature in axis grouping --
it blindly overlaps axis titles. I'll think what to do about this.

Also note that while all this features are included in axis/axistransf demoes,
your demo is less abstract, and so easier understandable.
I shall think about incorporating it.

Quote
Is there a way to increase the spacing between the title of one axis and the vertical line and tick marks of the next axis?
Another missing feature. I will fix that in a few days.
« Last Edit: March 03, 2012, 05:46:02 pm by Ask »

wp

  • Hero Member
  • *****
  • Posts: 13628
Re: TAchart: Multiple Axes
« Reply #2 on: March 03, 2012, 06:36:29 pm »
Thank you for the explanation and for the fix. Unfortunately I cannot compile this project because Lazarus (from a recent snapshot, Win32, FP2.6.0) crashes after loading ("Lazarus IDE does not work any more"). Other projects load without issues. What's wrong?

Quote
I shall think about incorporating it.
Feel free to use the example. I really appreciate the great number of demo examples that you collected. However, it is sometimes difficult to find the sample needed. I remember that there was a particular demo, but which one was it? Also, some demos combine several functions, and therefore look more complicated than they are. Maybe it would help to add a screen shot to each demo directory.


Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TAchart: Multiple Axes
« Reply #3 on: March 04, 2012, 02:23:35 am »
Quote
I cannot compile this project because Lazarus (from a recent snapshot, Win32, FP2.6.0) crashes after loading

Ouch. I have just updated Lazarus and the project opens fine for me.

You can try to run
lazarus.exe --debug-log=C:\lazarus\debug.log

And examine/post the resulting log file.

Also, here are my changes as unified diff,
so you can inspect them and apply by hand.
« Last Edit: March 04, 2012, 02:29:47 am by Ask »

wp

  • Hero Member
  • *****
  • Posts: 13628
Re: TAchart: Multiple Axes
« Reply #4 on: March 05, 2012, 08:30:27 pm »
Sorry for the late reply, I'm on a business trip.

I had caused Lazarus's crash by double-clicking the project file. Loading the project into a running instance of Lazarus is successful except for an error message due to a floating point error -- did not check into that.

Anyway, I see now what you mean: I just have to assign an AutoScaleTransform to each axis. I have to admit that the concept with the axis transformations is much more very powerful than the usual LogarithmicTransform that I am using routinely.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TAchart: Multiple Axes
« Reply #5 on: March 06, 2012, 09:56:53 am »
Quote
I had caused Lazarus's crash by double-clicking the project file. Loading the project into a running instance of Lazarus is successful except for an error message due to a floating point error -- did not check into that.

That may be a symptom of some bug in design-time code.
If you will be able to reproduce the issue, please post the debug log.


wp

  • Hero Member
  • *****
  • Posts: 13628
Re: TAchart: Multiple Axes
« Reply #6 on: March 07, 2012, 12:32:38 am »
Here is the debug log from my notebook that I am using at the moment (Win 7, 32-bit, Lazarus from yesterday's snapshot with FPC2.6.0). A double-click on the lpi file of the project, does load the project, but the error message on the invalid floating point operation appears. But I can compile the project. After I saved it without any changes it reloads without the error message.

On the pc at home, a double-click crashes Lazarus which does not start at all. I'll try to get the log file when I am back.
« Last Edit: March 07, 2012, 12:37:31 am by wp »

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TAchart: Multiple Axes
« Reply #7 on: March 07, 2012, 01:22:40 am »
The log does contain the stack trace, but without the symbols.
Can you recompile Lazarus with debug info enabled?

wp

  • Hero Member
  • *****
  • Posts: 13628
Re: TAchart: Multiple Axes
« Reply #8 on: March 07, 2012, 11:49:32 pm »
Sorry, should have known that... Anyway, here's the new log file. It is only partially written since Lazarus did not repsond any more during loading and I had to kill it by the task manager.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TAchart: Multiple Axes
« Reply #9 on: March 08, 2012, 01:06:39 pm »
Are you sure you recompiled Lazarus with Debug
("Configure rebuild Lazarus" -> Check "Debug", Check "Clean+build")?

This part of file:
Code: [Select]
TApplication.HandleException Invalid floating point operation
  Stack trace:
  $00C166A6
  $00C15DB7
...
should contain procedure names and line numbers.

Also, please delete log file before starting Lazarus -- otherwise,
new info is appended to the end of it.

wp

  • Hero Member
  • *****
  • Posts: 13628
Re: TAchart: Multiple Axes
« Reply #10 on: March 08, 2012, 04:37:17 pm »
Sorry I had not deleted the old one, but the requested data were at the end of the file. Anyway, here is a clean log again.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TAchart: Multiple Axes
« Reply #11 on: March 08, 2012, 06:35:31 pm »
Thanks for your patience.
Should be fixed in r35829.

wp

  • Hero Member
  • *****
  • Posts: 13628
Re: TAchart: Multiple Axes
« Reply #12 on: March 09, 2012, 11:57:46 pm »
Thank you

wp

  • Hero Member
  • *****
  • Posts: 13628
Re: TAchart: Multiple Axes
« Reply #13 on: March 18, 2012, 09:25:44 pm »
Coming back to the beautiful "paned" view of autoscaled series inside the same chart that you proposed above.

As you already noted, axis titles overlap if the indivual axes are in the same group. I tried to avoid this by using group 0 which separates the axes again, but retains the paned look. But the axis titles are drawn still in the center of the chart. I would prefer if they were in the center of each pane.

Additionally, the axis line is drawn over the entire height of the chart, I would prefer to have it only along its pane as well.

Finally, as can be seen in the attached screenshots, the range of axis labels is larger than in the non-paned view.

Is there a way how to restrict the axis to the panes and how to avoid the additional axes labels?

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TAchart: Multiple Axes
« Reply #14 on: March 19, 2012, 09:03:14 am »
Quote
As you already noted, axis titles overlap if the individual axes are in the same group
Since r36158 axis title is centered by the actual marks.
Note that this affects all axis titles unconditionally.
I hope that title position changes will be insignificant in the normal case,
but if you (or anybody) encounter a problem, I shall add a property to control this behavior.

Quote
Another question: Is there a way to increase the spacing between the title of one axis and the vertical line and tick marks of the next axis?
Added Axis.Margin property in r36159.

Quote
Is there a way how to restrict the axis to the panes and how to avoid the additional axes labels?
You can use Marks.Range property, see
http://wiki.lazarus.freepascal.org/TAChart_documentation#Axis_ranges

Quote
Additionally, the axis line is drawn over the entire height of the chart, I would prefer to have it only along its pane as well.
Some design decisions are needed here.
Do you think axis should be drawn along the axis range, marks range, marks range + some constant?
Should the user be able to control the above choice?
How should it interact with arrows?

 

TinyPortal © 2005-2018