Day of month axis label in chart

2 Answers 274 Views
Charts
J
Top achievements
Rank 1
Iron
Iron
J asked on 29 Jun 2021, 11:09 AM

Hi,

I have a chart with category axis of type 'Date', base units are set to 'days'.

I wonder how to tell the chart to show labels in format of 'day of month', i.e. 'd' (reference), because if I use either

type: 'Date',
baseUnit: 'days',
labels: {
  dateFormats: {
    days: 'd',
  },
}

or

type: 'Date',
baseUnit: 'days',
labels: {
  format: 'd'
}

it shows me '06/29/2021' instead of '29'.

 

Thanks for any advice.

J

 

2 Answers, 1 is accepted

Sort by
1
Accepted
Slavena
Telerik team
answered on 05 Jul 2021, 10:33 AM

Hi J,

Although combining the 'd' specifier with another one serves the requirement, it is not necessary. Since the formats take the {0: format} form, we could use the {0: d} option for this case. I have updated the Stackblitz demo correspondingly:

https://stackblitz.com/edit/angular-nsuajq-fbu2rf

I hope this helps. 

Regards,
Slavena
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

J
Top achievements
Rank 1
Iron
Iron
commented on 07 Jul 2021, 05:57 AM

Hi Slavena,

the curly brackets with the '0' placeholder seem to be the right solution.
Thanks for your help.

J
0
Slavena
Telerik team
answered on 01 Jul 2021, 11:03 AM

Hi J,

Thank you for the provided code snippets.

For more detailed information on formatting and parsing dates and numbers I would suggest referring to the following page from our documentation. In order to achieve the desired look of the Chart, the below formatting should be used:

<kendo-chart-category-axis-item [labels]="{ format: 'dd'}">

This approach is demonstrated in the Stackblitz demo below:

https://stackblitz.com/edit/angular-nsuajq

The different types of date formatting could be found in our public GitHub repository on Internationalization

https://github.com/telerik/kendo-intl/blob/develop/docs/date-formatting/index.md

I hope this helps. Let me know if i can provide further assistance on this case.

Regards,
Slavena
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

J
Top achievements
Rank 1
Iron
Iron
commented on 02 Jul 2021, 08:20 AM

Hi

I forgot to mention that required output is day of a month in format 1-31, not 01-31.
Thanks for the links provided - the github one
https://github.com/telerik/kendo-intl/blob/master/docs/date-formatting/index.md
showed me exactly the same as I posted with exactly the same confusing output, because:

"The d specifier—Renders a short date pattern: "M/d/y" for en."
formatDate(new Date(2000, 10, 6), "d"); // 10/6/2000

"The "d" specifier—Renders the day of the month."
formatDate(new Date(2000, 0, 1), "y d"); // 2000 1

Am I right that for using the second case there must be some other specifier (in this case 'y') to make it working as expected? I'd like to have just the date number.

Thanks for response.
J
Tags
Charts
Asked by
J
Top achievements
Rank 1
Iron
Iron
Answers by
Slavena
Telerik team
Share this question
or