-
Notifications
You must be signed in to change notification settings - Fork 981
Description
ScottPlot Version: 4.1.58.0
Operating System: Windows10
Application Type: WinForms
Question: The X-axis of DateTime mixture 24-hour and 12-hour notation.
Zoom in on a graph displaying DateTime data on the X-axis with the mouse wheel or right-click.
In this case, the 24-hour and 12-hour displays show different times, depending on whether they zoom to the nearest second or include milliseconds.
It appears that 24-hour notation is used for zooms that display up to seconds, and 12-hour notation is used for zooms that also display milliseconds.
Is this as expected?
| pattern | Actual output | comment |
|---|---|---|
| (A) Zooms that display up to seconds. | 1985/09/23 23:59:59 |
As expected. |
| (B) Zooms that also display milliseconds. | 1985/09/23 11:59:59.5 |
The time format expects 23:59:59.5. |
-
In case (A):
ScottPlot/src/ScottPlot4/ScottPlot/Ticks/DateTimeTickUnits/DateTimeTickUnitBase.cs
Lines 34 to 39 in 07ab190
protected virtual string GetTickLabel(DateTime value) { string date = value.ToString("d", culture); // short date string time = value.ToString("T", culture); // long time return $"{date}\n{time}"; } -
In case (B):
ScottPlot/src/ScottPlot4/ScottPlot/Ticks/DateTimeTickUnits/SecondsAndLess/DateTimeTickDecisecond.cs
Lines 25 to 30 in 07ab190
protected override string GetTickLabel(DateTime value) { string date = value.ToString("d", culture); // short date string time = value.ToString("hh:mm:ss.f", culture); // long time return $"{date}\n{time}"; }
Maybe HH is correct in (B) instead of hh?
The reproduced code is as follows:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ExecuteRecipe(formsPlot1.Plot);
}
private void ExecuteRecipe(Plot plt)
{
// original source: https://github.com/ScottPlot/ScottPlot/blob/07ab190973cbf8697ff8bdc98b4e6475ce40ea03/src/ScottPlot4/ScottPlot.Cookbook/Recipes/Axis.cs#L208-L222
// create data sample data
var myDates = new DateTime[1000]; // Change: 100 --> 1000
for (var i = 0; i < myDates.Length; i++)
myDates[i] = new DateTime(1985, 9, 24).AddMinutes(10 * i); // Change: .AddDays(7 * i) --> .AddMinutes(10 * i)
// Convert DateTime[] to double[] before plotting
var xs = myDates.Select(x => x.ToOADate()).ToArray();
var ys = DataGen.RandomWalk(myDates.Length);
plt.AddScatter(xs, ys);
// Then tell the axis to display tick labels using a time format
plt.XAxis.DateTimeFormat(true);
}
}