Skip to content

Commit

Permalink
Fix display width and height of canvas for non-responsive charts
Browse files Browse the repository at this point in the history
This is the final fix for vendrinc#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.
  • Loading branch information
mharmer committed Jun 5, 2019
1 parent a7ba9ae commit 66113f8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions webcomponent/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 66113f8

Please sign in to comment.