JSFiddle - React, Tailwind, and code Playground
HTML
<div id="chartContainer3" style="width: 100%; height: 300px;display: inline-block;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
JavaScript
var chart3 = new CanvasJS.Chart("chartContainer3", {
animationEnabled: true,
theme: "light2",
title:{
text: "Income"
},
axisX:{
interval: 1,
intervalType: "month",
valueFormatString: "YYYY-MM"
},
legend:{
cursor: "pointer",
//verticalAlign: "center",
//horizontalAlign: "right",
itemclick: toggleDataSeries
},
data: [ {
type: "column",
name: "Amount",
indexLabel: "{y}",
xValueFormatString: "YYYY-MM",
yValueFormatString: "$#0.##",
showInLegend: true,
dataPoints: [{"x":new Date("2018-05"),"y":15000},{"x":new Date("2018-06"),"y":9900}, {"x":new Date("2018-08"),"y":7000}] }]
});
chart3.render();
function toggleDataSeries(e){
if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
}
else{
e.dataSeries.visible = true;
}
chart3.render();
}