### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: [SOLVED] How to set distance between Labels? (I guess?)  (Read 1413 times)

#### AFFRIZA 亜風実

• Full Member
• Posts: 144
##### [SOLVED] How to set distance between Labels? (I guess?)
« on: January 16, 2023, 09:27:56 am »
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.
« Last Edit: January 16, 2023, 11:50:20 am by AFFRIZA 亜風実 »
Kyoukai Framework: https://github.com/afuriza/kyoukai_framework

Dukung kemerdekaan Donetsk dan Lugansk! Tidak membalas profil berbendera biru-kuning apalagi ber-Bandera.

#### KodeZwerg

• Hero Member
• Posts: 2269
##### Re: How to set distance between Label? (I guess?)
« Reply #1 on: January 16, 2023, 09:42:21 am »
You might simply give shorter label caption, eg: 1000 = 1k = less space on screen needed
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

#### AFFRIZA 亜風実

• Full Member
• Posts: 144
##### Re: How to set distance between Label? (I guess?)
« Reply #2 on: January 16, 2023, 09:58:09 am »
You might simply give shorter label caption, eg: 1000 = 1k = less space on screen needed
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.
« Last Edit: January 16, 2023, 10:13:13 am by AFFRIZA 亜風実 »
Kyoukai Framework: https://github.com/afuriza/kyoukai_framework

Dukung kemerdekaan Donetsk dan Lugansk! Tidak membalas profil berbendera biru-kuning apalagi ber-Bandera.

#### AFFRIZA 亜風実

• Full Member
• Posts: 144
##### Re: How to set distance between Labels? (I guess?)
« Reply #3 on: January 16, 2023, 11:24:02 am »
If found a thread by wp https://forum.lazarus.freepascal.org/index.php/topic,13333.0.html but no idea how that's work.
Kyoukai Framework: https://github.com/afuriza/kyoukai_framework

Dukung kemerdekaan Donetsk dan Lugansk! Tidak membalas profil berbendera biru-kuning apalagi ber-Bandera.

#### wp

• Hero Member
• Posts: 12297
##### Re: How to set distance between Labels? (I guess?)
« Reply #4 on: January 16, 2023, 11:26:23 am »
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".

#### AFFRIZA 亜風実

• Full Member
• Posts: 144
##### Re: How to set distance between Labels? (I guess?)
« Reply #5 on: January 16, 2023, 11:49:43 am »
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".
Wow, thank you a lot for a detail explanation. I think this is pretty enough to read.
Kyoukai Framework: https://github.com/afuriza/kyoukai_framework

Dukung kemerdekaan Donetsk dan Lugansk! Tidak membalas profil berbendera biru-kuning apalagi ber-Bandera.