[Chartjs]-How to make Chart JS responsive?

6👍

Chart.js has a property (responsive) that you can configure at the global or chart level via options that will make the chart responsive. See http://www.chartjs.org/docs/#getting-started-global-chart-configuration > responsive

// Boolean - whether or not the chart should be responsive and resize when the browser does.
responsive: true,

true makes it responsive. false (default) makes it non-responsive.


Example usage (only the relevant part, check out the CodePen for the full exam)

var ctx = $("#bar").get(0).getContext("2d");
var myChart = new Chart(ctx).Bar(barData, {
  responsive: true
});

CodePen – http://codepen.io/anon/pen/bdrGVx

You might also want to check out the maintainAspectRatio option, if you want to maintain the ratio of width to height.

Leave a comment