0

There is implementation of chartist tool tip plugin in a chartist, I like to know is it possible to change the date format to human readable as such DD-MM-YYYY.

    var chart = new Chartist.Line('.ct-chart', {
  labels: [1, 2, 3],
  series: [
    [
      {meta: 'description', x :new Date(parseInt(15433865410)), y: 25},

    ],
  ]
}, {
  plugins: [
    Chartist.plugins.tooltip()
  ]
});

In tooltip the x axis value shows as 15433865410, I need it to be DD-MM-YYYY. Any suggestion appreciated

Balaji.J.B
  • 618
  • 7
  • 14
  • Possible duplicate:https://stackoverflow.com/questions/11591854/format-date-to-mm-dd-yyyy-in-javascript – Just code Nov 28 '18 at 09:07
  • This is Chartist way of implementation. So, I need to call the function inside the chartist tool tip plugin. Which makes me confusing. I read the docs before positing the question. @just – Balaji.J.B Nov 28 '18 at 09:19
  • I think you can't put an string in `x` value of your code it will be always take an integer so you can't convert it into `dd-mm-yyyy`. – Shubham Baranwal Nov 28 '18 at 10:03
  • I know that @ShubhamBaranwal, because it wont plot the value, that why we should change the value inside the tooltip() function – Balaji.J.B Nov 28 '18 at 12:18

1 Answers1

0

You can't put an string value in x because it always takes an integer. But you can write in meta in date format dd-mm-yyyy. Here's my code -

var chart = new Chartist.Line('.ct-chart', {
  labels: [1, 2, 3],
  series: [
    [
      {meta: dateConvert(15433865410)+', '+ 25, x:new Date(parseInt(15433865410)), y: 25},

    ],
  ]
}, {
  plugins: [
    Chartist.plugins.tooltip()
  ]
});

function dateConvert(dateString){
  dateStr = new Date(parseInt(dateString));
  dateStr = dateStr.getDate() + '-' + ("0" + (dateStr.getMonth() + 1)).slice(-2) + '-' + dateStr.getFullYear();
  return dateStr;
} 
Shubham Baranwal
  • 2,492
  • 3
  • 14
  • 26