I have a chart with a large number of dates on the x axis, I have to set an initial “zoom” running from one month before the current date, up to one month after the current date.
I tried:
var fig = PlotlyFinance.createCandlestick(
{
open: Wopen,
high: Whigh,
low: Wlow,
close: Wclose,
dates: Wdates.map(function(d) { return new Date(d[0], d[1]-1, d[2]); })
});
var today = new Date();
var onemonback = new Date(new Date(today).setMonth(today.getMonth()-1));
var onemonafter = new Date(new Date(today).setMonth(today.getMonth()+1));
fig.layout.xaxis = {range: [new Date(onemonback.getFullYear, onemonback.getMonth()-1, onemonback.getDay()),new Date(onemonafter.getFullYear, onemonafter.getMonth()-1, onemonafter.getDay())]};
Plotly.newPlot(‘myDiv’, fig.data, fig.layout, {scrollZoom: true, modeBarButtonsToRemove: [‘hoverCompareCartesian’]});
It doesn’t work, how can I do?