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 . |
-
string time = value.ToString("T", culture); // long time
-
string time = value.ToString("hh:mm:ss.f", culture); // long 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);
}
}
X軸にDateTime
データを表示したグラフでマウスホイールや右クリックなどでズームします。
このとき、秒までをズームする場合とミリ秒を含めたズームとで時刻の表記が24時間表記と12時間表記とで異なります。
秒までを表示するズームでは24時間表記となり、ミリ秒も表示されるズームでは12時間表記となっているようです。
これは期待通りでしょうか?
パターン | 実際の出力 | コメント |
---|---|---|
(A) 秒までが表示されるズーム | 1985/09/23 23:59:59 |
期待通りです。 |
(B) ミリ秒も表示されるズーム | 1985/09/23 11:59:59.5 |
時刻の書式は 23:59:59.5 を期待しています。 |
-
string time = value.ToString("T", culture); // long time
-
string time = value.ToString("hh:mm:ss.f", culture); // long time
もしかして(B)では hh
ではなくて HH
が正しいのでしょうか?
再現コードは次の通りです:
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);
}
}