Fra*_*ank 4 javascript datetime-format plotly plotly.js
尝试使用plotly js 绘制日期图,但由于某种原因它显示时间和日期。
如何从该图中删除时间?谢谢!
x = ["2023-02-13", "2023-02-14"];
y = [3, 4];
var trace1 = {
type: "scatter",
mode: "lines",
name: '',
x: x,
y: y,
line: {color: '#17BECF'}
}
var layout = {
xaxis: {
type: 'date',
},
title: '',
};
var data = [trace1];
Plotly.newPlot('plotDiv', data, layout);
Run Code Online (Sandbox Code Playgroud)
我们可以在with 中指定刻度格式以避免包含时间。为了避免同一天的多个刻度重复相同的日期,我们还可以设置要使用的刻度之间的距离(根据文档,以秒为单位)。xaxislayouttickformat: '%b %d, %Y'1 daydtick: 86400000.0
可以在此处查看 codepen 。
var layout = {
xaxis: {
type: 'date',
tickformat: '%b %d, %Y',
dtick: 86400000.0
},
title: '',
};
Run Code Online (Sandbox Code Playgroud)