JSFiddle - React, Tailwind, and code Playground
by Eugen Sunic
HTML
<script src="http://www.chartjs.org/assets/Chart.js"></script>
<canvas id="myChart" width="700" height="400"></canvas>
<button type="button" class="yes" onclick="basDar()">Click Me!</button>
JavaScript
var array= [100, 59, 80, 333, 56, 55, 40]
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.5)",
strokeColor: "rgba(220,220,220,0.8)",
highlightFill: "rgba(220,220,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data: array
}
]
};
var options = {
animation: true
};
//Get the context of the canvas element we want to select
var ctx = document.getElementById("myChart").getContext("2d");
/*************************************************************************/
myNewChart = new Chart(ctx).Bar(data, options);
function basDar()
{ alert("yes");
for (var i=0; i<7; i++){ myNewChart.removeData();}
array= [100, 200, 300, 333, 400, 555, 700]
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.5)",
strokeColor: "rgba(220,220,220,0.8)",
highlightFill: "rgba(220,220,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data: array
}
]
};
var options = {
animation: true
};
myNewChart = new Chart(ctx).Bar(data, options);
}