Unplanned
Last Updated: 30 Oct 2023 13:40 by Adam
Adam
Created on: 30 Oct 2023 13:40
Category: Charts
Type: Feature Request
2
Render culture-aware labels on the date axis

Enhance the Chart date axis label format, so that it's culture-aware in globalization scenarios, and there is no need to set ChartCategoryAxisLabels Format explicitly.

In the meantime, here are a few workarounds for the case when the ChartCategoryAxis BaseUnit is Days and the Chart shows MM/dd labels even to non-US users.

  • The easier option is to use a standard format string:
<ChartCategoryAxis BaseUnit="ChartCategoryAxisBaseUnit.Days"
                    Type="ChartCategoryAxisType.Date">
    <ChartCategoryAxisLabels Format="d" />
</ChartCategoryAxis>
  • The above contains the year, so another option is MonthDayPattern:
<ChartCategoryAxis BaseUnit="ChartCategoryAxisBaseUnit.Days"
                    Type="ChartCategoryAxisType.Date">
    <ChartCategoryAxisLabels Format="@( CultureInfo.CurrentUICulture.DateTimeFormat.MonthDayPattern )" />
</ChartCategoryAxis>

Razor

<ChartCategoryAxis BaseUnit="ChartCategoryAxisBaseUnit.Days"
                    Type="ChartCategoryAxisType.Date">
    <ChartCategoryAxisLabels Format="@( GetShortDayMonthPattern() )" />
</ChartCategoryAxis>

C#

    private string GetShortDayMonthPattern()
    {
        var mdp = CultureInfo.CurrentUICulture.DateTimeFormat.MonthDayPattern;
        var separator = CultureInfo.CurrentUICulture.DateTimeFormat.DateSeparator;
        string pattern = mdp.IndexOf("M") < mdp.IndexOf("d") ? $"MM{separator}dd" : $"dd{separator}MM";

        return pattern;
    }

Regards, Author nickname Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
0 comments