Recent

Author Topic: Doubble log graph not showing main marks  (Read 1869 times)

Firebird

  • New Member
  • *
  • Posts: 26
Doubble log graph not showing main marks
« on: July 10, 2023, 01:04:02 pm »
I created a double log graph and defined the position of marks by sources. This basically works fine. However, the "main marks" pow(10, x) with x integer do not regularly show on the axis (see attached image). Is there a means to define these marks "superior" (mark hierarchy) to other marks so they are displayed as axis marks for sure?

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: Doubble log graph not showing main marks
« Reply #1 on: July 10, 2023, 02:53:55 pm »
Creation of log charts is largely simplified in Laz 3.0+. Here the Axis.Intervals.Option contain a new option aipInteger which forces the labeller to place marks only at integer values - in case of the log chart these transform to the powers of 10 (10^0 = 1, 10^1 = 10, 10^2 = 100, 10^3 = 100). To get the intermediate labels I would recommend to add a minor chart axis. - see attached demo "log_log_Laz3"

If you use an older version of Lazarus you should add a TListChartSource into which you load the label that you want to see; otherwise it is hard to control that labels appear only at the powers of 10. see attached demo "log_log_Laz2". In this demo the steps to add the minor axes are done by instructions in the source code so that you can see more easily which steps are important (I hope I did not forget some). In the other demo, the steps are applied in the object inspector at designtime.

Firebird

  • New Member
  • *
  • Posts: 26
Re: Doubble log graph not showing main marks
« Reply #2 on: July 12, 2023, 08:07:47 pm »
Thank you, the graph layout looks nice. In my case minor and major marks still overlap. I have attached a graph I did with gnuplot for a log x-axis. Is it possible to generate something like that (log x-axis) using TAChart? I did not find a means to assign a text via "source" to minor marks.

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: Doubble log graph not showing main marks
« Reply #3 on: July 13, 2023, 12:53:16 am »
I committed a version of the TAChart axis units in which the minor axes can have a Source for the mark positions like in the main axes. The files are in the main branch of the Lazarus gitlab repository, they will not be back-ported to the upcoming Laz 3.0 since this is a new feature and may pose some stability risk. If you are using the v3.0RC1, however, there is a good chance that you may be able to merge the new code into your TAChart: download the files tachartaxis.pas and tachartaxisutils.pas from https://gitlab.com/freepascal.org/lazarus/lazarus/-/tree/main/components/tachart and write them over the same file in your existing installation (they are in folder (lazarus)/components/tachart - but make a backup copy first). Then recompile the IDE (menu "Tools" > "Build Lazarus with profile..."). (I am not sure whether this will work with Laz 2.2.6).

I am attaching a modified version of my previous demo project. It adds two ListChartSources, xMinorMarksSource and yMinorMarksSource, which contain the Marks positions and their text for the x and y axes. The text is always the mantissa of the mark value (i.e., '5' rather than '5000'). Separate sources were used because the larger mark values in each decade tend to overlap in case of the y axis, and thus the marks for 7 and 9 do not get a label here. Of course, a single chartsource could be used for both axes as well, and the Marks.OverlapPolicy could be set to opHideNeighbour; however, this results in some instable label positions when the window size is changed.

For the main marks I decided to switch to exponential format, i.e. a short "10^6" rather than a long "1,000,000". In order to display "nice" exponents I switched the Marks.TextFormat to tfHTML and used the axes' OnGetMarkText event to send the mark text as HTML with "sup" tags.

Firebird

  • New Member
  • *
  • Posts: 26
Re: Doubble log graph not showing main marks
« Reply #4 on: July 13, 2023, 07:01:26 am »
Thank you very much WP. I followed your instructions and could recompile the new project provided by you with my current Lazarus IDE version 2.2.4. The result looks nice. I will try to add it to the project I am working on at the moment. Thanks again!

 

TinyPortal © 2005-2018