Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Difficulty controlling X-axis time display in auto-scale mode

Auto-scale mode is great in that I can zoom and pan and all the axes are updated, but the display of time is not very controlable. I specifically want the start and end time to always be displayed on the far right and left, and I want a decent number of subdivisions to always be displayed. In auto-scale mode non of this appears to be controllable. What can I do short of taking over control of all aspects of the chart scaling and axes control to get auto-scale behavior that is more reasonable?

Thank you,
Martin
0 Kudos
Message 1 of 6
(4,686 Views)
It's impossible for the axis auto division spacing to always automatically do exactly what you want. In these cases, it's a bit of manual work, but nowhere near as much as controlling scaling and axes for customized auto scaling behavior.

When auto spacing isn't producing what you want, you can set the axis AutoSpacing property to false, and then add an event handler for the axis RangeChanged event. When the range changes, you can look at the range and determine what a good looking interval will be, then configure Base and Interval properties on the axis MajorDivisions and MinorDivisions to make it look exactly like you want.

- Elton
Message 2 of 6
(4,686 Views)
Great answer. I was able to solve most of my problems intercepting said event and forcing divisions of 4 major and 4 minor inbetween. Now my only problem is that the right side of the chart extends to the end and cuts off the DateTime label of the axis...

private void m_chart_XAxisRangeChanged(object sender, NationalInstruments.UI.XAxisEventArgs e)
{
e.XAxis.AutoSpacing = false;
Range range = e.XAxis.Range;
double interval = range.Maximum - range.Minimum;

e.XAxis.MajorDivisions.Base = range.Minimum;
e.XAxis.MinorDivisions.Base = range.Minimum;
e.XAxis.MajorDivisions.Interval = interval / 3;
e.XAxis.MinorDivisions.Interval = interval / 12;
}

How would I extend this to find logical rounded off time intervals such as 3
:00pm rather than 2:49pm is the next question..

Thanks!
mturon
0 Kudos
Message 3 of 6
(4,686 Views)
I don't completely understand the problem. Could you please attach a screenshot, or better yet, a small test project that demonstrates the problem? Thanks.

- Elton
0 Kudos
Message 4 of 6
(4,686 Views)
Hopefully a picture is worth a thousand words..

I think this has something to do with Mode = AutoScaleLoose or something along those lines.
Download All
0 Kudos
Message 5 of 6
(4,686 Views)
Hmm ... looking at the screenshot, I'm not 100% sure of what would fix it. Did you try another axis mode, like AutoScaleExact, as you mentioned? Did it make a difference? Also, regarding your question about extending the example to find logical rounded time intervals, I think the best way to do this is to actually look at your range in terms of DateTime values instead of double values. Notice that Range has DateTime equivalents for the Minimum/Maximum properties called MinimumDateTime/MaximumDateTime. You could look at these values and adjust them by assigning a new Range with the rounded values if they are not what you want. Be careful if you do this, though, since this will result in another RangeChanged event and you
could end up in a recursive loop if you keep setting the Range to a different value.

If this does not help, could you please create a small test application that demonstrates the problem and attach it, then post how you want to the test application to behave? Thanks.

- Elton
0 Kudos
Message 6 of 6
(4,686 Views)