For my plugin, I am drawing a graph in a panel using CanvasJS. The graph is drawn in a <div>
element with the id ‘chartContainer’. I am trying to make sure that the size of the graph adjusts if the size of the panel is adjusted. However, this works with the width, but not with the height. I am doing it like this:
The function loadGraph() is called whenever the panel is initialized.
loadGraph() {
this.chart = new CanvasJS.Chart("chartContainer", {
backgroundColor: "#1f1d1d",
height: this.$element.parent().innerHeight()- 40,
width: this.$element.parent().innerWidth() - 40,
axisY: {
includeZero: false
},
data: [{
type: "scatter",
dataPoints: this.dps
}, { type: "line", dataPoints: this.curveData }]
});
this.chart.render();
}
The function onRender() is called whenever the ‘render’ event takes place.
onRender() {
console.log("onRender is called");
console.log('height is: ', this.$element.parent().innerHeight());
console.log('width is: ', this.$element.parent().innerWidth());
this.chart = new CanvasJS.Chart("chartContainer", {
backgroundColor: "#1f1d1d",
height: this.$element.parent().innerHeight()- 40,
width: this.$element.parent().innerWidth() - 40,
axisY: {
includeZero: false
},
data: [{
type: "scatter",
dataPoints: this.dps
}, { type: "line", dataPoints: this.curveData }]
});
this.chart.render();
}
As you can see, the way I set the height is identical to the way I set the width. However, this works only for the width, the height does not adjust (in the picture below, you can see that the heigth of the graph (P-V curve) is much more than the height of the panel).
Does anyone know how to fix this? Thanks in advance!