JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<div id="chartContainer" style="height: 360px; width: 100%;"></div>
JavaScript
//Creating a multi-series line graph from 2 sets of data. Namely dps1 and dps2.
var dps1 = [{ x: 0, y: 10 }, { x: 2, y: 17 }, { x: 3, y: 29 }]; //dataPoints – line 1
var dps2 = [{ x: 1, y: 15 }, { x: 2, y: 28 }, { x: 3, y: 42 }]; //dataPoints. – line 2
var chart = new CanvasJS.Chart("chartContainer", {
title:{
text: "Earthquakes - per month"
},
axisX: {
minimum: new Date(2012, 01, 1),
maximum: new Date(2012, 11, 1),
},
data: [
{
type: "line",
//xValueType: "dateTime",
indexLabel: "Some label",
indexLabelTextAlign: "right",
dataPoints: []
}
]
// end of data for 2 line graphs
}); // End of new chart variable
chart.render();
checkIfNoDataPoints();
function checkIfNoDataPoints() {
for(var i = 0; i < chart.options.data.length; i++) {
if(chart.options.data[i].dataPoints.length == 0) {
chart.options.data[i].dataPoints.push({x:chart.axisX[0].get("minimum"), y:0, color: "transparent", toolTipContent: null, indexLabel: " "})
}
}
chart.render();
}