TAchart: Multiple Axes lazarus / 55-TAChart ---------------------------------------------------------------------- wp · 2012-03-03 15:54 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 · 2012-03-03 16:43 QuoteEach 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. QuoteIs 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. ---------------------------------------------------------------------- wp · 2012-03-03 17:36 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? QuoteI 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 · 2012-03-04 01:23 QuoteI 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. ---------------------------------------------------------------------- wp · 2012-03-05 19:30 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 · 2012-03-06 08:56 QuoteI 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 · 2012-03-06 23:32 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. ---------------------------------------------------------------------- Ask · 2012-03-07 00:22 The log does contain the stack trace, but without the symbols. Can you recompile Lazarus with debug info enabled? ---------------------------------------------------------------------- wp · 2012-03-07 22:49 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 · 2012-03-08 12:06 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 · 2012-03-08 15:37 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 · 2012-03-08 17:35 Thanks for your patience. Should be fixed in r35829. ---------------------------------------------------------------------- wp · 2012-03-09 22:57 Thank you ---------------------------------------------------------------------- wp · 2012-03-18 20:25 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 · 2012-03-19 08:03 QuoteAs you already noted, axis titles overlap if the individual axes are in the same groupSince 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. QuoteAnother 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. QuoteIs 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 QuoteAdditionally, 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? ---------------------------------------------------------------------- wp · 2012-03-19 08:43 Thank you. I really appreciate your work. Attached is a new screen shot (created using svn), it is almost perfect. I restricted the Marks.Range to draw Marks only for values > 0, and for the pressure axis only for values < 2000, but the minor ticks are still there because there is no Marks.Range property for minors. But I think this is not the problem. Can it be that something is wrong with finding the first and last mark in case of the paned view? As you can see in the previous posting, marks finding is correct for the non-paned view. QuoteSome 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? Well, I was thinking of the marks range, maybe with some constant. I did not use the arrows so far, but they would look best if they were at the end of the drawn axis. BTW: What is the axis property Attachment for? ---------------------------------------------------------------------- Ask · 2012-03-19 12:27 Quoteminor ticks are still thereShould be fixed in r36164-36165 QuoteWhat is the axis property Attachment for? It is inherited from TChartMarks: http://wiki.lazarus.freepascal.org/TAChart_documentation#Mark_position s_and_attachment. Mostly useless for axis titles -- maybe except for the case when you want the title to be drawn directly over the axis. ---------------------------------------------------------------------- wp · 2012-03-19 15:01 Fine! Thank you. With another data file I am getting a new issue with marks positioning. As you can see in the attached screen shot the marks for the pressure axis are drawn only up to 40 although the data go up to 60. I set up a simple demo project which shows the same effect. The red axis in this demo is for two overlaid (red) sine curves, the one with amplitude 1, the other one with amplitude 2. Marks, however, are drawn only for the curve with amplitude 1. If the Marks property AtDataOnly is set as in this example, it seems to me that selection of marks seems to consider only the first series attached to an axis. ---------------------------------------------------------------------- Ask · 2012-03-20 15:03 QuoteIf the Marks property AtDataOnly is set as in this example, it seems to me that selection of marks seems to consider only the first series attached to an axis. Indeed. This is because when implementing it I was unsure how to process this case. There are two possibilities: 1) Prepare axis marks for each series separately. This would be useful for if the series data are spatially separated from each other. 2) Calculate a union of value ranges for all series, then generate marks for that range. This is preferable for overlapping series. Since I do not use AtDataOnly myself, I postponed the decision until I get some feedback. You are the first user of this feature, so you get to decide ---------------------------------------------------------------------- wp · 2012-03-20 16:56 QuoteYou are the first user of this feature, so you get to decide I feel honored... When reading your answer I got the feeling that using AtDataOnly is maybe the wrong way. I modified the demo, let AtDataOnly at false but used the Range property to restrict the label range. I had been confused about the units of the range parameter, but it seems to be in "world" coordinates. Now the demo runs as I want it, see the attached screen shot. If you still want to modify the behavior of AtDataOnly, I'd prefer the second option because I think it is more general.