score:15

Accepted answer

ok i have tried this solution and it works.

        <canvas id="bar"
                height="100"
                width="100"
                class="chart chart-bar" 
                chart-data="datachart"
                chart-labels="labels"
                chart-click="onclick"
                chart-options="options">
        </canvas>

or defining the size as like a style in a css-class.

score:0

chart uses its parent container to update the canvas render and display sizes. however, this method requires the container to be relatively positioned and dedicated to the chart canvas only. responsiveness can then be achieved by setting relative values for the container size

score:1

the problem is that the height and width attribute values are stored in the chart and are not updated in the same way that the other attributes are. to fix this you have to add a listener to the create event and manually change the height in the chart object

html:

<canvas
    id="chart"
    class="chart chart-horizontal-bar"
    chart-data="chart.data"
    chart-labels="chart.data.labels"
    chart-series="chart.series"
    chart-options="chart.options"
    chart-colors="chart.colors"
    height="{{ comparechart.height }}"
    width="{{ comparechart.width }}"
></canvas>

js:

$scope.$on('chart-create', function (event, chart) {
    chart.chart.height = $scope.chart.height;
});

you would expect $scope.chart.height to change during an ajax lookup or something that will bring in new data.

score:4

to define height of charts according to the screen size, i use this code :

in controllers

$scope.height_chart = window.innerheight*0.7;

in template

<canvas height="{{height_chart}}" class="chart chart-line" data="weight.data" labels="weight.labels" series="weight.series"></canvas>

i hope these codes will help.

score:7

you can also wrap the <canvas> into a <div>, like so:

<div style="height:300px;width:300px;">
    <canvas
            class="chart chart-radar"
            chart-data="$ctrl.data"
            chart-options="options"
            chart-labels="$ctrl.labels"></canvas>
</div>

setting the width and height like in the other answers did not work for me.


Related Query

More Query from same tag