This is a migrated thread and some comments may be shown as answers.

How to display a string as a date on a cart axis

6 Answers 23 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Iron
Iron
Iron
Lee asked on 13 May 2020, 07:00 PM
I have data that returns a date as a string in the format of yyyymmdd (e.g. 20200112). I need to display this on the X axis of a kendo line chart as yyyy-mm-dd (2020-01-12). How would I do that? I tried in the model but got various parse errors. 

6 Answers, 1 is accepted

Sort by
0
Lee
Top achievements
Rank 1
Iron
Iron
Iron
answered on 13 May 2020, 09:28 PM
I'm using webpack with babel to compile the code. I looked at this article but there weren't any responses: https://stackoverflow.com/questions/59595371/how-do-i-allow-the-kendo-controls-to-use-custom-js-functions-when-i-use-webpack
0
Vessy
Telerik team
answered on 15 May 2020, 01:11 PM

Hi Lee,

The built-in date-formating functions in Kendo can parse andf format only standard JavaScript DateTime objects. Nevertheless, you can achieve the target result by implementing a custom categoryAxis.labels.template, formating the received string on your own with some simple client-side logic.

You can see a sample demonstrating a possible approach for such implementation here:

https://dojo.telerik.com/IVaSuXAc

Regards,
Vessy
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Lee
Top achievements
Rank 1
Iron
Iron
Iron
answered on 15 May 2020, 02:56 PM
The problem seems to be accessing a function in compiled code. Once the code is compiled the function no longer is available to the kendo ui template. 
0
Vessy
Telerik team
answered on 19 May 2020, 11:55 AM

Hi Lee,

Have you tried moving the template function to a separate, not-copmiled js file (like the approach you have shared in your other thread)? If this is not possible, you can include the formatDate() fucntion logic directly inside the template of the labels:

http://dojo.telerik.com/EzAFuYUl

                    categoryAxis: {
                        labels: {
                            template: "#= kendo.format('{0}-{1}-{2}', value.substr(0, 4), value.substr(4, 2), value.substr(6, 2)) #"
                        },
                    }

Regards,
Vessy
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Lee
Top achievements
Rank 1
Iron
Iron
Iron
answered on 19 May 2020, 12:52 PM
Thank you. Both solutions sound good. I tried the first one and it works. I like the latter one better but have not tried it yet.
0
Vessy
Telerik team
answered on 20 May 2020, 10:33 AM

Hi,

You are welcome, Lee - i am glad the proposed solutions served their purposes.

Let us know whenever any further question about our widgets occurs.

Regards,
Vessy
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Charts
Asked by
Lee
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Lee
Top achievements
Rank 1
Iron
Iron
Iron
Vessy
Telerik team
Share this question
or