DayOfWeek as Category label

1 Answer 113 Views
Charts
Ilan
Top achievements
Rank 1
Bronze
Iron
Veteran
Ilan asked on 10 May 2023, 01:17 PM

I'm using

ChartCategoryAxis Type="@ChartCategoryAxisType.Date" BaseUnit="@ChartCategoryAxisBaseUnit.Fit"

Is there a way to show the labels as DayOfWeek (Wednesday) instead of date (3/1) ?

1 Answer, 1 is accepted

Sort by
0
Yanislav
Telerik team
answered on 15 May 2023, 07:51 AM

Hi Ilan,

You can show the name of the day of the week as text, but you need to set up a label template. This lets you turn the label value into a JavaScript Date object, which has a really handy method called getDay(). This method gives you a number that represents the day of the week. From there, you can use another function to turn that number into the day's name. 

<ChartCategoryAxisLabels Template="#=dayOfWeekAsString(new Date(value).getDay())#"></ChartCategoryAxisLabels>

<script suppress-error="BL9992">
    window.dayOfWeekAsString = (dayIndex)=> {
      return ["Sunday", "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][dayIndex] || '';
    }
</script>

To demonstrate the approach I've prepared a REPL example: https://blazorrepl.telerik.com/QxYJvzOz54qUSfbt36

I hope this helps. 

Regards,
Yanislav
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!
Tags
Charts
Asked by
Ilan
Top achievements
Rank 1
Bronze
Iron
Veteran
Answers by
Yanislav
Telerik team
Share this question
or