<title>Bar Chart</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="../dist/Chart.bundle.js"></script>
- <style type="text/css">
- canvas {
- border: 1px solid red;
- }
+ <style>
+ canvas {
+ -moz-user-select: none;
+ -webkit-user-select: none;
+ -ms-user-select: none;
+ }
</style>
</head>
<body>
- <div id="container" style="width: 50%; height: 25%;">
- <canvas id="canvas" height="450" width="600"></canvas>
+ <div id="container" style="width: 75%;">
+ <canvas id="canvas"></canvas>
</div>
<button id="randomizeData">Randomize Data</button>
<button id="addDataset">Add Dataset</button>
<button id="removeDataset">Remove Dataset</button>
<button id="addData">Add Data</button>
<button id="removeData">Remove Data</button>
- <button id="show">Show</button>
- <div>
- <h3>Legend</h3>
- <div id="legendContainer">
- </div>
- </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);
};
};
- function updateLegend() {
- $legendContainer = $('#legendContainer');
- $legendContainer.empty();
- $legendContainer.append(window.myBar.generateLegend());
- }
-
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx, {
},
title: {
display: true,
- text: 'Our 3 Favorite Datasets'
+ text: 'Chart.js Bar Chart'
}
}
});
- updateLegend();
};
$('#randomizeData').click(function() {
});
window.myBar.update();
- updateLegend();
});
$('#addDataset').click(function() {
barChartData.datasets.push(newDataset);
window.myBar.update();
- updateLegend();
});
$('#addData').click(function() {
if (barChartData.datasets.length > 0) {
- barChartData.labels.push('data #' + barChartData.labels.length);
+ var month = MONTHS[barChartData.labels.length % MONTHS.length];
+ barChartData.labels.push(month);
for (var index = 0; index < barChartData.datasets.length; ++index) {
//window.myBar.addData(randomScalingFactor(), index);
}
window.myBar.update();
- updateLegend();
}
});
$('#removeDataset').click(function() {
barChartData.datasets.splice(0, 1);
window.myBar.update();
- updateLegend();
});
$('#removeData').click(function() {
});
window.myBar.update();
- updateLegend();
- });
-
- $('#show').click(function() {
- document.getElementById('container').style.display = '';
});
</script>
</body>