Skip to content

Crosshair and Axis Line: Support custom label formatters #1172

@Maoyao233

Description

@Maoyao233

Features Suggestion

Feature description: In #1100 , a custom formatter can be used to format the tick lables, but crosshair doesn't support it, which leads to inconsistencies in the label display. It might be possible to add CustomLabelFormatX and CustomLabelFormatY to solve this problem. I can make a pull request if needed.

Code example:

plt.AddSignal(ScottPlot.DataGen.Sin(51));
plt.AddSignal(ScottPlot.DataGen.Cos(51));

var crosshair = plt.AddCrosshair(10, 0);

// create a custom formatter as a static class
static string customLabelFormatter(double position)
{
    if (position == 0)
        return "zero";
    else if (position > 0)
        return $"+{position:F2}";
    else
        return $"({Math.Abs(position):F2})";
}

// use the custom formatter for horizontal and vertical tick labels
plt.XAxis.TickLabelFormat(customLabelFormatter);
plt.YAxis.TickLabelFormat(customLabelFormatter);

// use the custom formmater for crosshair labels
crosshair.CustomLabelFormatX(customLabelFormatter);
crosshair.CustomLabelFormatY(customLabelFormatter);

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