Destroy chart.js bar graph to redraw other graph in same

The correct method to use, in order to be able to draw another chart on the same canvas, is .destroy(). You must call it on the previously created chart object. You may also use the same variable for both charts. var grapharea = document.getElementById(“barChart”).getContext(“2d”); var myChart = new Chart(grapharea, { type: ‘bar’, data: barData, options: … Read more

Different color for each bar in a bar chart; ChartJS

As of v2, you can simply specify an array of values to correspond to a color for each bar via the backgroundColor property: datasets: [{ label: “My First dataset”, data: [20, 59, 80, 81, 56, 55, 40], backgroundColor: [“red”, “blue”, “green”, “blue”, “red”, “blue”], }], This is also possible for the borderColor, hoverBackgroundColor, hoverBorderColor. From … Read more

Setting width and height [closed]

You can override the canvas style width !important … canvas{ width:1000px !important; height:600px !important; } also specify responsive:true, property under options.. options: { responsive: true, maintainAspectRatio: false, scales: { yAxes: [{ ticks: { beginAtZero:true } }] } } update under options added : maintainAspectRatio: false, link : http://codepen.io/theConstructor/pen/KMpqvo

How to clear a chart from a canvas so that hover events cannot be triggered?

I had huge problems with this First I tried .clear() then I tried .destroy() and I tried setting my chart reference to null What finally fixed the issue for me: deleting the <canvas> element and then reappending a new <canvas> to the parent container My specific code (obviously there’s a million ways to do this): … Read more

Chart.js : straight lines instead of curves

Solution for Version 1 (old charts version) According to documentation on chartjs.org you can set the ‘bezierCurve’ in options and pass it in when you create the chart. bezierCurve: false eg: var options = { //Boolean – Whether the line is curved between points bezierCurve : false }; var myLine = new Chart(document.getElementById(“canvas”).getContext(“2d”)).Line(lineChartData, options); Update … Read more