JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE HTML>
<head>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div>
<input type="button" class="btn btn-default" value="Purge" onclick="Close();">
<input type="button" class="btn btn-default" value="Re-plot" onclick="rePlot();">
</div>
<div id="graphDiv">
</div>
<script type="text/javascript">
var TSPlot = {
layout: {
yaxis: {
rangemode: "tozero",
},
xaxis: {
type: 'date',
},
showlegend: true
},
traces: []
};
var trace = {
mode: 'lines',
y: [3, 5, 1, 3, 4, 2],
x: [1551802506000,1551802536000,1551802567000,1551802597000,1551802627000,1551802657000]};
var update = {
'yaxis.rangemode': "tozero",
'xaxis.type': "date"
};
var newlayout = {
yaxis: {
rangemode: "tozero"
},
xaxis: {
type: "date"
}
};
function rePlot(){
TSPlot.traces.push(trace);
Plotly.newPlot('graphDiv', TSPlot.traces, TSPlot.layout, {
responsive: true,
displayModeBar: false
});
}
function Close() {
Plotly.relayout('graphDiv', newlayout);
Plotly.purge('graphDiv');
TSPlot.traces = [];
}
rePlot();
</script>
</body>