google.charts.load('current', {
callback: drawChart,
packages: ['corechart']
});
function drawChart() {
var data = [
[new Date("2017-09-11T10:58:14.580+03:00"), 8],
[new Date("2017-09-11T10:59:22.013+03:00"), 16],
[new Date("2017-09-11T11:13:23.344+03:00"), 18],
[new Date("2017-09-11T11:14:00.608+03:00"), 6],
[new Date("2017-09-11T11:14:18.877+03:00"), 20],
[new Date("2017-09-11T11:14:29.214+03:00"), 16]
];
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('date', 'Time');
dataTable.addColumn('number', 'On');
var xTicks = [];
data.forEach(function (row, index) {
// add begin & end ticks
xTicks.push(row[0]);
xTicks.push(new Date(row[0].getTime() + (row[1] * 1000)));
// add rows
// start line at 0
dataTable.addRow([row[0], 0]);
// move line up to 1
dataTable.addRow([row[0], 1]);
// move line across for number of seconds
dataTable.addRow([new Date(row[0].getTime() + (row[1] * 1000)), 1]);
// bring line back down to zero
dataTable.addRow([new Date(row[0].getTime() + (row[1] * 1000)), 0]);
// break line
dataTable.addRow([new Date(row[0].getTime() + (row[1] * 1000)), null]);
});
var chart = new google.visualization.LineChart(document.getElementById('chart1'));
chart.draw(dataTable, {
chartArea: {
bottom: 60
},
hAxis: {
format: 'H:s',
slantedText: true,
ticks: xTicks
},
vAxis: {
ticks: [
{v: 0, f: 'OFF'},
{v: 1, f: 'ON'},
{v: 2, f: ''}
]
}
});
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart1"></div>
是的,它可以幫助一個很多,ThankYou –