Skip to content

DateTimeTickUnits: The X-axis of DateTime mixture 24-hour and 12-hour notation. #2132

@MareMare

Description

@MareMare

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.

Maybe HH is correct in (B) instead of hh?

Animation

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);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions