Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Axis scaling problem

Assume that you don't want to use AutoSpacing and wants to define the man and min of the axis manually.
Here is the code that I used:

private void Form1_Load(object sender, System.EventArgs e)
{
double min = -1.01;
double max = 3.6783;
double diff = max - min;
Random rnd = new Random();
double[] data = new double[100];
for (int i = 0; i < data.Length; i++)
data[i] = rnd.NextDouble() * diff + min;
waveformPlot1.PlotY(data);
yAxis1.AutoSpacing = false;
yAxis1.MajorDivisions.Base = min;
yAxis1.MajorDivisions.Interval = diff / 5.0;
}
and here is the result:
(Attachment: Axis.JPG)
As you see, there is no min and max on the Yaxis.
0 Kudos
Message 1 of 4
(3,405 Views)
I believe the problem is the Axis Mode of the graph. Set the Axis Mode of the graph to fixed and set the range of the Y Axis. You were not including the class namespace for "NationalInstruments.UI". This is required to set the Axis Mode of the Y Axis. I made changes to the code so that the graph shows the max and min values at the top and bottom of the graph respectively.

Tyler T.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,386 Views)
Agree, but it does not solve the problem if you want to limit the number of digits after the decimal point (rounding). I modified your code a little bit and I got the same problem:

// Set the Range of the Y Axis
yAxis1.Range = new NationalInstruments.UI.Range(Math.Round(min, 3), Math.Round(max, 3));

yAxis1.MajorDivisions.Base = Math.Round(min, 3);
yAxis1.MajorDivisions.Interval = Math.Round(diff / 5.0, 3);
0 Kudos
Message 3 of 4
(3,378 Views)
The value you are using for diff has to be exactly that of the range. So for this code use:

yAxis1.MajorDivisions.Interval = (Math.Round(max, 3) - Math.Round(min, 3)) / 5.0;

If you are using the real value for diff (the unrounded values), then range is slightly off from diff and the intervals are off enough so that the top value is not displayed on the graph. Replace your code with the above line and it should work properly.

Tyler T
Applications Engineer
National Instruments
0 Kudos
Message 4 of 4
(3,358 Views)