Forum > TAChart

[SOLVED] How to set distance between Labels? (I guess?)

(1/2) > >>

AFFRIZA 亜風実:
So, I'm really new to TAChart. I want to make a something like an app to read audio graph file from txt but the graph is kind of hard to read (second screenshot attachment).
Is that possible to set a distances between labels in the bottom axis like in the first screenshot in attachment?

Demo in the zip attachment.

KodeZwerg:
You might simply give shorter label caption, eg: 1000 = 1k = less space on screen needed

AFFRIZA 亜風実:

--- Quote from: KodeZwerg on January 16, 2023, 09:42:21 am ---You might simply give shorter label caption, eg: 1000 = 1k = less space on screen needed

--- End quote ---
How about set the bottom axis distance like 0 to 200 is 1/3 of chart width, 200 to 2000 also 1/3 of chart width, and 2000 to 20000 is 1/3 of chart width. So those parts will be stretched.

Like the bass area is 20Hz to 200Hz, I want to highlight that by stretching into 1/3 of chart width. Same with the midrange 200Hz to 2000Hz.

AFFRIZA 亜風実:
If found a thread by wp https://forum.lazarus.freepascal.org/index.php/topic,13333.0.html but no idea how that's work.

wp:
In order to prevent overlapping labels you should increase the value of the Intervals.MaxLength of the chart's BottomAxis to something like 120. This is the maximum distance between adjacent label positions before the labeling procedure switches to next label base.

Doing this will result in linear axis labels (see attachment "linear_axis"). The image that you give as a reference, however, has a logarithmic axis, i.e. the distance between 20 and 200, between 200 and 2000 and between 2000 and 20000 is the same.

Some more steps are required in TAChart to create a log plot:

* Drop a TChartAxisTransformations component to the form. Assign it to the Transformations property of the chart's BottomAxis
* Select the line series in the object tree above the object inspector, and set its AxisIndexX to 1 - this is the index of the bottom axis and has the consequence that the original x values of your data set are transformed in the way defined by the AxisTransformations component.
* Double-click on the AxisTransformations property and add a Logarithmi transform.
* Set the Base of the LogarithmAxisTransform to 10.
* It is usually quite tricky to achieve nice automatically placed axis labels with a log axis transform. Therefore, I recommend to do this manually: Add a TListChartSource to the form. Assign it to the Marks.Source property of the chart's BottomAxis, and set Marks.Style to smsXValue. This means that the chart will use the values listed in the ListChartSource as labels of the x axis.
* In order to enter the label positions click on the DataPointsProperty of the ListChartSource, and enter the numbers 1, 10, 100, 1000, 10000 and 100000 in the x column.
* When you now run the project you will see a nice log axis with labels at 100, 1000 and 10000 (the others are not inside the plotting range).
* If you want intermediate ticks you should add a minor axis to the chart's BottomAxis: Click on the '...' button next to the BottomAxis.Minors. Click "Add", select the new minor axis (labeled as '0 - M') and set its Intervals property to 9 (between 1 and 10 we want 9 additional intervals: 1-2,2-3,3-4,4-5,5-6,6-7,7-8,8-9,9-10. You may also want to have the minor grid a bit more decent: set Grid.Color of the minor axis to clSilver. Setting the Marks.Style of the minor axis to smsValue you could label the minor axis - but I do not recommend this since the labels at the end of the decade very probably will overlap, and there is not way to control the position of the minor labels manually.See attachment "logarithmic_axis".

Navigation

[0] Message Index

[#] Next page

Go to full version