Reputation: 394
I have a simple time series chart from 0 to 5 seconds.
GraphPane pane = zedGraph.GraphPane;
pane.XAxis.Type = AxisType.Date;
pane.XAxis.Scale.Format = "mm:ss.fff";
pane.XAxis.Scale.Min = new XDate(2011, 2, 5, 0, 0, 0, 0);
pane.XAxis.Scale.Max = new XDate(2011, 2, 5, 0, 0, 5, 0);
pane.YAxis.Scale.MajorStep = 1;
pane.YAxis.Scale.Min = -1.0;
pane.YAxis.Scale.Max = 3.0;
zedGraph.IsEnableWheelZoom = true;
zedGraph.AxisChange();
zedGraph.Invalidate();
Minor ticks should be less than 1 second. But zedgraph doesn't show every last minor tick before each major tick.
If I zoom-out to the minor scale > 1 second, it appears normally. When I change major and minor scales, there may be several ticks missing before major tick:
pane.XAxis.Scale.MajorUnit = DateUnit.Second;
pane.XAxis.Scale.MajorStep = 1;
pane.XAxis.Scale.MinorUnit = DateUnit.Second;
pane.XAxis.Scale.MinorStep = 0.10;
Does Zedgraph has some limitations dealing with minor tick scales in milliseconds?
Upvotes: 0
Views: 490
Reputation: 14839
Looks like this an issue in the Axis.DrawMinorTics
method.
Axis values are doubles, and XDate
uses lets say days as its base unit, 2011,2,5 and 2011,2,5,0,0,5 are converted to doubles as 40579.0 and 40579.000057870522
When calculating whether or not to draw the minor tick, an epsilon value is used to compare the tick value with the next major value. That epsilon in this case is 1e-10. This comparison calculation begins to get very small given the base using of XDate
is so large compared to milliseconds.
How can you resolve this:
If you are using the source directly you can update Axis.DrawMiorTicks to use a smaller epsilon. 1e-20 should be small enough.
If a binary release is used (such as a nuget package) you can offset all your date values by the start value so that the dates are much smaller and calculations are less likely to get that small.
var start = new XDate(2011, 2, 5);
pane.XAxis.Scale.Min = new XDate(2011, 2, 5, 0, 0, 0, 0) - start;
pane.XAxis.Scale.Max = new XDate(2011, 2, 5, 0, 0, 5, 0) - start;
this however is not a guarantee that it will not happen again with some values, as XDate is using days as a base unit and scaling to millisecond level this will eventually happen again.
A better solution would be to make seconds or even milliseconds your base unit and not use the AxisType.Date
setting at all, and connect to the ScaleFormatEvent
event of the XAxis
to format your values manually.
Upvotes: 1