JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdn.canvasjs.com/canvasjs.min.js"></script>
<div id="container" style="overflow: hidden">
<div id="chartContainer" style="height: 360px; width: 100%; "></div>
</div>
JavaScript
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",{
zoomEnabled: true,
rangeChanged: function () {
elem.style.right = chart._toolBar.offsetWidth + 8 + 'px';
},
title:{
text: "Enable Zooming Dynamically"
},
axisX:{
title: "axisX Title",
},
data: [
{
type: "column",
dataPoints: [
{ x: 10, y: 71 },
{ x: 20, y: 55 },
{ x: 30, y: 50 },
{ x: 40, y: 65 },
{ x: 50, y: 95 },
{ x: 60, y: 68 },
{ x: 70, y: 28 },
{ x: 80, y: 34 },
{ x: 90, y: 14 }
]
}
]
});
chart.render();
var options = ['x', 'y', 'xy'];
var elem = document.createElement("select");
elem.style.position = 'absolute';
elem.style.top = "9px";
elem.style.right = chart._toolBar.offsetWidth + 5 + 'px';
elem.style.height = '27px';
elem.style.border = "1px solid #2196f3";
elem.style.backgroundColor = "#fff";
chart.container.appendChild(elem);
elem.addEventListener("change", function(e){
setZoomType(chart, e.target.value);
});
for(var i = 0; i < 3; i++) {
var option = document.createElement('option');
option.value = options[i];
option.innerText = options[i];
elem.appendChild(option);
}
function setZoomType(chart, zoomType) {
chart.set('zoomType', zoomType);
}
}