Skip to content

Instantly share code, notes, and snippets.

@frontrangerider2004
Created December 3, 2015 23:50
Show Gist options
  • Save frontrangerider2004/cf8171353eca8f4bebaa to your computer and use it in GitHub Desktop.
Save frontrangerider2004/cf8171353eca8f4bebaa to your computer and use it in GitHub Desktop.
chart-bar suggested fix for not rendering
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="chart-js-import.html">
<link rel="import" href="dataset-properties-behavior.html">
<link rel="import" href="context-behavior.html">
<link rel="import" href="resize-behavior.html">
<link rel="import" href="chart-styles.html">
<dom-module id="chart-bar">
<template>
<style include="chart-styles"></style>
<canvas id="canvas"></canvas>
</template>
<script>
Polymer({
is: 'chart-bar',
behaviors: [
ChartBehaviors.DatasetPropertiesBehavior,
ChartBehaviors.ContextBehavior,
ChartBehaviors.ResizeBehavior
],
updateChart: function () {
if(this.isAttached){ //Check for attach otherwise our ctx and chart will be undefined, resulting in no render
this.async(function () {
if (this.chart) {
this.chart.destroy();
}
this.async(function() {
this.chart = new Chart(this.ctx).Bar(this.data, this.options);
}, null, 0);
}, null, 0);
} else {
console.log("udpateChart() DOM isn't ready!");
}
},
//Always called after ready, which means our canvas element will exist
//This enables us to render the chart the first time on page load an retain our update method for updates
attached: function() {
this.updateChart();
},
});
</script>
</dom-module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment