简体   繁体   English

在图表专家提示插件中显示日期(DD-MM-YYY)格式?

[英]show date (DD-MM-YYY) format in chartist tool-tip plugin?

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. 图表专家中有图表专家工具提示插件的实现,我想知道是否可以将日期格式更改为诸如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. 在工具提示中,x轴值显示为15433865410,我需要将其设置为DD-MM-YYYY。 Any suggestion appreciated 任何建议表示赞赏

You can't put an string value in x because it always takes an integer . 您不能在x中放入string值,因为它始终需要一个integer But you can write in meta in date format dd-mm-yyyy . 但是您可以使用日期格式dd-mm-yyyymeta中编写。 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;
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM