Thursday, August 22, 2013

C# ChartAreas zoom event to redraw labels

C# ChartAreas zoom event to redraw labels

I'm using Microsoft Visual Studio 2010 (C#) .NET 4.0 to do a chart. I've
enabled a zoom feature.
The Data can span several days and needs to be "zoomable" to within about
10-20 seconds.
// Compute how long between each label.
// It will differ depending if we are dealing with a timespan of days,
if (TimeSpanOfGraph > new TimeSpan(24, 0, 0)) {
DateTimeInterval = DateTimeIntervalType.Minutes;
IntervalPeriod = 15;
}
else if (TimeSpanOfGraph > new TimeSpan(6, 0, 0)) {
DateTimeInterval = DateTimeIntervalType.Seconds;
IntervalPeriod = 30;
}
else if (TimeSpanOfGraph > new TimeSpan(1, 0, 0)) {
DateTimeInterval = DateTimeIntervalType.Seconds; IntervalPeriod = 1;
}
else {
DateTimeInterval = DateTimeIntervalType.Seconds;
IntervalPeriod = 1;
}
MasterPlot.ChartAreas[PlotNumber].AxisX.Title = "Absolute time";
MasterPlot.ChartAreas[PlotNumber].AxisX.LabelStyle.Format = "MM/dd HH:mm";
MasterPlot.ChartAreas[PlotNumber].AxisX.LabelStyle.IntervalType =
DateTimeInterval;
MasterPlot.ChartAreas[PlotNumber].AxisX.LabelStyle.Interval = IntervalPeriod;
If I make the DateTimeInterval and IntervalPeriod too long, it won't show
up when I zoom (it'll only show "Thursday" for one point). If I make it
too narrow, it'll try to draw a label for every minute over three days. If
I set IntervalType to Auto, I get "MM/dd" as my label. :)
Curious if anyone can suggest the proper way to do this. Ditto for Y axis.

No comments:

Post a Comment