简体   繁体   中英

Doughnut chart adjusting problem in chart.js

Whenever I change the page resolution or size or zooming in the page chartjs adjust charts, its okay. But when undo my last action it doesn't come back its original size. Actually its get bigger in every action that I made on the page.

This is what i want:
这就是我要的

this is what happens when i zoom:
这是我缩放时发生的情况

 function doughnut_config(data, labels, center_text, tooltip_enabled = true) { const config = { type: 'doughnut', data: { datasets: [{ data: data, backgroundColor: backgroundColor, borderWidth: 0.3 }], labels: labels }, options: { legend: false, responsive: true, maintainAspectRatio: false, elements: { center: { text: center_text } }, tooltips: { enabled: tooltip_enabled } } }; return config; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script> <div class="col-lg-6" style="text-align: center;"> <canvas id="my_chart" style="height: 160px; "></canvas> </div>

Please make sure to use max-height style on your canvas.

for example:

<canvas id=“my_chart" style="max-height: 160px;"></canvas>

还尝试以 % 值而不是像素给出高度和宽度。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM