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

7 posts, 0 answers
  1. Lee
    Lee avatar
    70 posts
    Member since:
    May 2019

    Posted 13 May Link to this post

    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. 
  2. Lee
    Lee avatar
    70 posts
    Member since:
    May 2019

    Posted 13 May Link to this post

    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
  3. Vessy
    Admin
    Vessy avatar
    2162 posts

    Posted 15 May Link to this post

    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.
  4. Lee
    Lee avatar
    70 posts
    Member since:
    May 2019

    Posted 15 May in reply to Vessy Link to this post

    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. 
  5. Vessy
    Admin
    Vessy avatar
    2162 posts

    Posted 19 May Link to this post

    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.
  6. Lee
    Lee avatar
    70 posts
    Member since:
    May 2019

    Posted 19 May in reply to Vessy Link to this post

    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.
  7. Vessy
    Admin
    Vessy avatar
    2162 posts

    Posted 20 May Link to this post

    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.
Back to Top