Charts 谷歌图表API日历图表

Charts 谷歌图表API日历图表,charts,google-api,google-visualization,google-calendar-api,Charts,Google Api,Google Visualization,Google Calendar Api,我正在使用GoogleCharts API进行数据可视化。我想在图表上检索所选日期 我找回的东西很奇怪。。我正在使用文档推荐的图表上的selectHandler function selectHandler() { console.log(chart.getSelection()[0]); } google.visualization.events.addListener(chart, 'select', selectHandler); 单击以下日期,我在控制台上读取

我正在使用GoogleCharts API进行数据可视化。我想在图表上检索所选日期

我找回的东西很奇怪。。我正在使用文档推荐的图表上的selectHandler

  function selectHandler() {

    console.log(chart.getSelection()[0]);

  }

  google.visualization.events.addListener(chart, 'select', selectHandler);
单击以下日期,我在控制台上读取以下输出:

2020年4月22日:15875136000

2020年6月19日:1592524800000

这是什么样的日期格式?
有人能帮我吗

这是自Unix纪元以来以毫秒数表示的日期。
它与日期对象上的
getTime()
返回的值相同

您可以将从选择中收到的值传递给日期构造函数以获取日期

var selection = chart.getSelection();
if (selection.length > 0) {
  var selectedDate = new Date(selection[0].date);
}
请参阅以下工作片段

google.charts.load('current'{
套餐:[“日历”]
}).然后(函数(){
var dataTable=new google.visualization.dataTable();
addColumn({type:'date',id:'date'});
addColumn({type:'number',id:'Won/Loss'});
dataTable.addRows([
[新日期(2012年3月13日),37032],
[新日期(2012年3月14日),38024],
[新日期(2012年3月15日),38024],
[新日期(2012年3月16日),38108],
[新日期(2012年3月17日),38229],
[新日期(2013年9月4日),38177],
[新日期(2013年9月5日),38705],
[新日期(2013年9月12日),38210],
[新日期(2013年9月13日),38029],
[新日期(2013年9月19日),38823],
[新日期(2013年9月23日),38345],
[新日期(2013年9月24日),38436],
[新日期(2013年9月30日),38447]
]);
var chart=new google.visualization.Calendar(document.getElementById('Calendar_basic');
变量选项={
标题:“红袜队出席人数”,
身高:350,
};
函数selectHandler(){
var selection=chart.getSelection();
如果(selection.length>0){
var selectedDate=新日期(选择[0]。日期);
console.log(selectedDate);
}
}
google.visualization.events.addListener(图表'select',selectHandler);
图表绘制(数据表、选项);
});

谢谢!我已经准备好了。。当心!