diff --git a/src/core/core.helpers.js b/src/core/core.helpers.js index 0b9cea52eb3..b3d4b3f8317 100644 --- a/src/core/core.helpers.js +++ b/src/core/core.helpers.js @@ -544,8 +544,10 @@ module.exports = function(Chart) { // If no style has been set on the canvas, the render size is used as display size, // making the chart visually bigger, so let's enforce it to the "correct" values. // See https://github.com/chartjs/Chart.js/issues/3575 - canvas.style.height = height + 'px'; - canvas.style.width = width + 'px'; + if (!canvas.style.height && !canvas.style.width) { + canvas.style.height = height + 'px'; + canvas.style.width = width + 'px'; + } }; // -- Canvas methods helpers.fontString = function(pixelSize, fontStyle, fontFamily) { diff --git a/test/specs/core.helpers.tests.js b/test/specs/core.helpers.tests.js index dc865fb01b2..9da7bd093fc 100644 --- a/test/specs/core.helpers.tests.js +++ b/test/specs/core.helpers.tests.js @@ -745,6 +745,23 @@ describe('Core helper tests', function() { document.body.removeChild(div); }); + it ('should leave styled height and width on canvas if explicitly set', function() { + var chart = window.acquireChart({}, { + canvas: { + height: 200, + width: 200, + style: 'height: 400px; width: 400px;' + } + }); + + helpers.retinaScale(chart, true); + + var canvas = chart.canvas; + + expect(canvas.style.height).toBe('400px'); + expect(canvas.style.width).toBe('400px'); + }); + describe('Color helper', function() { function isColorInstance(obj) { return typeof obj === 'object' && obj.hasOwnProperty('values') && obj.values.hasOwnProperty('rgb');