score:15
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.
Source: stackoverflow.com
Related Query
- Changing width and height in angular-chart.js module
- Chart.js: width and height of a pie chart not respected
- How to get the actual chart width and height in chart.js
- Changing width of chart.js chart without changing height
- React chart : prevent chart's canvas scaling with height and width
- Why would a ChartJS chart end up with width 0 and height 0?
- Unable to set width and height on canvas in chart js
- attempting to change height and width of canvas for chart
- Prevent size of canvas chart js to equal window height and width
- Setting width and height
- Problem for display a chart with Chart.js and Angular
- How to use PrimeNg Chart of Width and Height?
- Resize the width and height of the ng2-charts
- Width and Height in Chart.js
- ERROR TypeError: "this.canvas is undefined" | Problem with creating a chart with angular and chart.js
- Keep chart.js doughnut with fixed width and height centered in container
- Remove additional white space on left and right side of Angular Chart
- Css style not working well when resizing chart height in angular application
- Changing Dataset for a chart in angular 10
- canvas does not display proper width and height chart.js
- I can not properly re scale <canvas> with width and height attributes
- How to style a pie chart in chart js? I want to change the border color, border width and give them shadow
- Chart.js and Angular - Click Event on Chart
- Bar chart with min height and zero values - ChartJs
- how to increase space between legend and chart in chartjs (ng2charts ) using angular
- Chart.js canvas and chart width gets overwritten when redrawn
- Binding Chart to Canvas height width
- How to set responsive width and height of canvas?
- Customise size of data points , height and width in Chart.js?
- Html canvas element resets width and height to zero after drag/drop
More Query from same tag
- Chart.js - changing tick / label positions for x axis time series
- How do I change axis, title, legend formatting on chartjs template
- Chart.js doughnut text colors
- How can I use an array of {x,y} objects to make a chart?
- How could chartjs font family display everywhere
- ChartJs - pie chart not showing
- Pie chart.js - display a no data held message
- Using array as data in Chart.js
- Foreground chart by mouse
- chart.js version 3 - How to make an overlapping bar chart?
- Mixed chart barchart won't show
- Possible to merge 2 bars in bar chart (chart.js)
- How to add label square to Bar Chart using Chart.js
- Prime NG Customise tool tip on Bar Chart
- onClick : handleClick
- Chart.js is it possible to style the labels?
- Dynamically set data on Angular-chart.js
- first and last value is not displaying in chart.js used with django
- How to underline and bold tooltip chart js
- How to draw multiple color bar in a bar chart using chart.js
- How to remove background color and color example from tooltip in Chart.js?
- Resize pie chart from chart.js
- Chartjs v2.8 showAllTooltips does not exist
- ChartJS 3 doesn't display legend
- Styling background (fill) with ChartJs and React
- ChartJS: Horizontal Bar with multiple datasets not showing Bars
- specify bar width for a single bar
- Display Date Label in axes - chart js/ng2 charts
- Updating chart.js chart with dataset of different size
- Need help splitting date to new line in Doughnut Chart js