Integer Axis labels

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
quarz
Posts: 14
Joined: Mon Nov 11, 2013 11:23 am
Location: Russia, Moscow

Integer Axis labels

Post by quarz » Fri Nov 16, 2018 3:05 pm

Hello.
I want to draw a signal on the graph that can only take integer values.
How do I set Y axis so that the labels take only integer values even when zooming?

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: Integer Axis labels

Post by ArctionKestutis » Mon Nov 19, 2018 8:15 am

Hello,

Not sure how 'axis could take integer values' but I assume it is about label's string format and magnitude of division. Here is brief guide on subject.
Disable auto-formatting and use set label's string in any way user likes. User can use normal formatting string here, same as you he/she use to ToString() method (default ‘0.0’). See for references MSDN: Custom Numeric Format Strings and MSDN: Standard Numeric Format Strings.
The simplest way:

Code: Select all

            _chart.ViewXY.YAxes[0].AutoFormatLabels = false;
            _chart.ViewXY.YAxes[0].LabelsNumberFormat = "0";
If user is planning to zoom-in (with LabelsNumberFormat = "0"), then it is good idea to disable other Axis' auto format properties.
In particular, user should set

Code: Select all

            _chart.ViewXY.YAxes[0].AutoDivSpacing = false; 
and use ONLY one of following properties to set division:

Code: Select all

            _chart.ViewXY.YAxes[0].MajorDiv = 1;
            _chart.ViewXY.YAxes[0].MajorDivCount = 5;
depending on which property he want to keep fixed, the following property should be set accordingly. E.g., to keep 'MajorDiv' as primary reference property:

Code: Select all

            _chart.ViewXY.YAxes[0].KeepDivCountOnRangeChange = false;
Finally, if range changes several magnitudes, you may need further adjustment to those properties (if 'auto' formatting is not used). The easiest way to do that is to subscribe to Axis.RangeChanged event and modify all required properties in event handler.

Hope this helps.

quarz
Posts: 14
Joined: Mon Nov 11, 2013 11:23 am
Location: Russia, Moscow

Re: Integer Axis labels

Post by quarz » Tue Nov 20, 2018 10:11 am

Thank you, it works!

Post Reply