JSFiddle - React, Tailwind, and code Playground
by canvasjs
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/><!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>
JavaScript
var chart = new CanvasJS.Chart("chartContainer",
{
title:{
text: "Converting in Local Time"
},
axisX:{
title: "time",
gridThickness: 2,
interval:2,
intervalType: "hour",
valueFormatString: "hh TT K",
labelAngle: -25,
labelFormatter: function(e){
if(e.chart.axisX[0].minimum === e.value.getTime())
return "";
return CanvasJS.formatDate(e.value, e.axis.valueFormatString);
}
},
axisY:{
title: "distance"
},
data: [
{
type: "line",
dataPoints: [//array
{x: new Date(Date.UTC (2012, 01, 1, 1,0) ), y: 26 },
{x: new Date( Date.UTC (2012, 01, 1,2,0) ), y: 38 },
{x: new Date( Date.UTC(2012, 01, 1,3,0) ), y: 43 },
{x: new Date( Date.UTC(2012, 01, 1,4,0) ), y: 29},
{x: new Date( Date.UTC(2012, 01, 1,5,0) ), y: 41},
{x: new Date( Date.UTC(2012, 01, 1,6,0) ), y: 54},
{x: new Date( Date.UTC(2012, 01, 1,7,0) ), y: 66},
{x: new Date( Date.UTC(2012, 01, 1,8,0) ), y: 60},
{x: new Date( Date.UTC(2012, 01, 1,9,0) ), y: 53},
{x: new Date( Date.UTC(2012, 01, 1,10,0) ), y: 60}
]
}
]
});
chart.render();