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?
Integer Axis labels
Moderator: Queue Moderators
-
- Posts: 557
- Joined: Mon Mar 14, 2016 9:22 am
Re: Integer Axis labels
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:
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
and use ONLY one of following properties to set division:
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:
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.
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";
In particular, user should set
Code: Select all
_chart.ViewXY.YAxes[0].AutoDivSpacing = false;
Code: Select all
_chart.ViewXY.YAxes[0].MajorDiv = 1;
_chart.ViewXY.YAxes[0].MajorDivCount = 5;
Code: Select all
_chart.ViewXY.YAxes[0].KeepDivCountOnRangeChange = false;
Hope this helps.
Re: Integer Axis labels
Thank you, it works!