Ng2-charts: How to set a charts height.

Created on 20 Jul 2016  路  3Comments  路  Source: valor-software/ng2-charts

Sorry for the lame question.

How do I set a chart's height using ng2-charts? I'm making a line chart, just like the demo on the ng2-charts site.

I've searched the documentation for ng2-charts and chart.js. In chart.js it looks like you set a height property on the canvas element like <canvas height="400">, but that element is obscured by the ng2-charts component.

In my options I have responsive: true and maintainAspectRatio: false. Just need to set the height I want now.

Most helpful comment

Figured it out.
If responsive: true and maintainAspectRatio: false is set, you can the height of the <base-chart> element.

All 3 comments

Figured it out.
If responsive: true and maintainAspectRatio: false is set, you can the height of the <base-chart> element.

@brandonreid how did you exactly set the height? I can't seem to get the right combination.

Edit:

<base-chart
   ....
   [style.height]="graph.height + 'px'"
   ....
   >
</base-chart>

And remove any height stuff from CSS like I had height: auto !important; inside a .chart rule.

@philjones88 did you set the <base-chart> to display: block;?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dslima90 picture dslima90  路  3Comments

grahammutter picture grahammutter  路  4Comments

vmironovs picture vmironovs  路  3Comments

alexcastillo picture alexcastillo  路  5Comments

mrpotato3 picture mrpotato3  路  5Comments