From 66113f8faaf39f679f88bc43006412276876f568 Mon Sep 17 00:00:00 2001 From: mharmer Date: Wed, 5 Jun 2019 13:32:35 -0700 Subject: [PATCH] Fix display width and height of canvas for non-responsive charts This is the final fix for #3 to properly set the canvas size when using a non-responsive chart. If responsive is used, this width and height seem to be ignored and the chart should properly size to the window dimensions. --- webcomponent/chart.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webcomponent/chart.js b/webcomponent/chart.js index 618fce1..a9e5a27 100644 --- a/webcomponent/chart.js +++ b/webcomponent/chart.js @@ -95,6 +95,12 @@ customElements.define( this.appendChild(canvasContainer) const canvas = this.getElementsByTagName("canvas")[0] + + // Setup the display size of the canvas to match the requested width/height, + // this will normally only work if the option responsive field is set to False. + canvas.width = this.getAttribute("chartWidth") + canvas.height = this.getAttribute("chartHeight") + const ctx = canvas.getContext("2d") this._chart = new Chart(ctx, this._chartConfig) }