Pie Chart is not fitting with in Canvas
See original GitHub issueExpected behavior
The pie chart should fit in the canvas. The pie chart should display the legend at the bottom, it display it at the top The pie chart is not showing the title , when I provided it n the configurations.
How should I display values on the pie chart without having to hover over it.
Current behavior
The pie chart exceeds the canvas The legend is on top when I specified it ot be in the bottom. The title is not appearing
Reproducible sample
I dont have one
Optional extra steps/info to reproduce
This is my code in components.ts
let chartCanvas = document.getElementById('chart-sector') as HTMLCanvasElement;
let chartData = {
labels: Array.from(this.sector_data.keys()),
datasets: [{
label: 'Reports By Sector',
data: Array.from(this.sector_data.values()),
backgroundColor: this.generateRandomColors(_.size(this.sector_data)),
options: {
responsive: false,
plugins: {
legend: {
position: 'bottom',
},
title: {
display: true,
text: 'Reports By Sector'
}
}
},
}],
};
this.sectorChart = new Chart(chartCanvas.getContext("2d"), {
type: 'pie',
data: chartData
});
This is the code on the html
<div class=" col-md-4">
<div class=" card">
<div class=" card-body">
<div class=" col-auto">
<div class=" chart row">
<canvas class=" chart-canvas" id="chart-sector"></canvas>
</div>
</div>
</div>
</div>
</div>
This is how I imported Chartjs
import { Chart, registerables } from "chart.js";
Chart.register(...registerables);
This is how my chart appears
Possible solution
No response
Context
No response
chart.js version
v3.9.1
Browser name and version
Chrome 104.0.5112.81 and microsoft edge 104.0.1293.47
Link to your project
No response
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Charts.js graph not scaling to canvas size - Stack Overflow
The width and height property that you set for the canvas only work if the Chartjs' responsive mode is false (which is true...
Read more >Show data in a line, pie, or bar chart in canvas apps
Add a pie chart On the Insert tab, select Charts, and then select Pie Chart. Move the pie chart under the Import data...
Read more >Chart Container - Concepts - Handbook - Apache ECharts
If the height and width of the container do not exist, or you wish the chart size not equal to the container, you...
Read more >Pie chart - MATLAB pie - MathWorks
This MATLAB function draws a pie chart using the data in X. ... If you specify a conversion character that does not fit...
Read more >Responsive Charts - Chart.js
Furthermore, these sizes are independent from each other and thus the canvas render size does not adjust automatically based on the display ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@stockiNail , what was making my other graphs dissapear was something else, so your solution has worked! Thanks
Got the solution to my probem
here: https://stackoverflow.com/questions/67058279/chart-js-types-of-property-type-are-incompatible-type-string-is-not-assigna
I added as any at the end of th chart creation because TypeScript compiler is complaining because the chart type property is a specific type rather than a string