Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

カスタム DateTime ラベル形式

ユーザーは、DateTime の目盛りラベルをカスタマイズするための独自のロジックを提供できます

ScottPlot.Plot myPlot = new();

// サンプルの DateTime データをプロットする
DateTime[] dates = Generate.ConsecutiveDays(100);
double[] ys = Generate.RandomWalk(100);
myPlot.Add.Scatter(dates, ys);
myPlot.Axes.DateTimeTicksBottom();

// RenderStarting イベントにロジックを追加して目盛りラベルをカスタマイズする
myPlot.RenderManager.RenderStarting += (s, e) =>
{
    Tick[] ticks = myPlot.Axes.Bottom.TickGenerator.Ticks;
    for (int i = 0; i < ticks.Length; i++)
    {
        DateTime dt = DateTime.FromOADate(ticks[i].Position);
        string label = $"{dt:MMM} '{dt:yy}";
        ticks[i] = new Tick(ticks[i].Position, label);
    }
};

myPlot.SavePng("demo.png", 400, 300);
このレシピは、軸と目盛りカテゴリにある多数のレシピの 1 つです