102 lines
3.4 KiB
HTML
Executable File
102 lines
3.4 KiB
HTML
Executable File
<!doctype html>
|
|
<html>
|
|
|
|
<head>
|
|
<title>Horizontal Bar Chart Zoom</title>
|
|
<script src="../node_modules/chart.js/dist/Chart.bundle.js"></script>
|
|
<script src="../node_modules/hammerjs/hammer.min.js"></script>
|
|
<script src="../chartjs-plugin-zoom.js"></script>
|
|
|
|
<style>
|
|
canvas {
|
|
-moz-user-select: none;
|
|
-webkit-user-select: none;
|
|
-ms-user-select: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="container" style="width: 75%;">
|
|
<canvas id="canvas"></canvas>
|
|
</div>
|
|
|
|
<script>
|
|
var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
|
|
var randomScalingFactor = function() {
|
|
return (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100);
|
|
};
|
|
var randomColorFactor = function() {
|
|
return Math.round(Math.random() * 255);
|
|
};
|
|
var randomColor = function() {
|
|
return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
|
|
};
|
|
|
|
var barChartData = {
|
|
labels: ["January-16", "February-16", "March-16", "April-16", "May-16", "June-16", "July-16", "August-16", "September-16", "October-16", "November-16", "December-16", "January-17", "February-17", "March-17", "April-17", "May-17", "June-17", "July-17", "August-17", "September-17", "October-17", "November-17", "December-17"],
|
|
datasets: [{
|
|
label: 'Dataset 1',
|
|
backgroundColor: "rgba(220,220,220,0.5)",
|
|
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
|
|
}, {
|
|
hidden: false,
|
|
label: 'Dataset 2',
|
|
backgroundColor: "rgba(255,187,205,1)",
|
|
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
|
|
}, {
|
|
label: 'Dataset 3',
|
|
backgroundColor: "rgba(151,187,205,0.5)",
|
|
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
|
|
}]
|
|
|
|
};
|
|
|
|
window.onload = function() {
|
|
var ctx = document.getElementById("canvas").getContext("2d");
|
|
window.myBar = new Chart(ctx, {
|
|
type: 'horizontalBar',
|
|
data: barChartData,
|
|
options: {
|
|
// Elements options apply to all of the options unless overridden in a dataset
|
|
// In this case, we are setting the border of each bar to be 2px wide and green
|
|
elements: {
|
|
rectangle: {
|
|
borderWidth: 2,
|
|
borderColor: 'rgb(0, 255, 0)',
|
|
borderSkipped: 'bottom'
|
|
}
|
|
},
|
|
responsive: true,
|
|
legend: {
|
|
position: 'top',
|
|
},
|
|
title: {
|
|
display: true,
|
|
text: 'Chart.js Bar Chart'
|
|
},
|
|
pan: {
|
|
enabled: true,
|
|
mode: 'y'
|
|
},
|
|
zoom: {
|
|
enabled: true,
|
|
mode: 'xy'
|
|
},
|
|
scales: {
|
|
yAxes: [{
|
|
ticks: {
|
|
min: 'April-16',
|
|
max: 'August-16'
|
|
}
|
|
}]
|
|
}
|
|
}
|
|
});
|
|
};
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|