简体   繁体   English

如何增加圆环图或饼图的大小并将图例保留在图表JS中?

[英]How to increase the size of the donut or pie chart and keep the legend next to it in chart JS?

This is how the donut chart looks with the legend这就是带有图例的圆环图的外观

在此处输入图像描述

And when I set legend -> display to false this is how the donut chart looks当我将 legend -> display 设置为 false 时,这就是甜甜圈图的外观

在此处输入图像描述

I want the donut size to be as big as the second photo along with the legend next to it on the right like the first photo.我希望甜甜圈的大小和第二张照片一样大,右边的图例和第一张照片一样。

Please suggest how to go about this请建议如何 go 关于这个

the code is as follows:代码如下:

CSS: CSS:

#monthly_chart{
            border: 0px solid black;
            height: 300px;
            width: 300px;
            margin-left: auto;
            margin-right: auto;
        }

HTML: HTML:

<div id="monthly_chart">
    <canvas id="monthly_chart_content"></canvas>
</div>

Javascript: Javascript:

var ctx = document.getElementById('monthly_chart_content').getContext('2d');
  var chart = new Chart(ctx, {

    type: 'doughnut',

    data: {
        labels: client_data,
        datasets: [{
            label: 'Grey Inwards',
           backgroundColor: ["#1b3862","#0078c6","#00552c","#2d9a27","#fcfa43","#fbbe00","#fe7d00","#e73300","#cb247f","#8636ca","#d3d3d3","#31343d"],
            data: grey_data,

        }]
    },

    // Configuration options go here
    options: {
        aspectRatio: 1,
        responsive: false,
        maintainAspectRatio: true,
        cutoutPercentage: 70,
        legend: {
            display: true,
            position: 'right',
            labels: {
                boxWidth: 20,
                }
            },


    }
});

Value of display property is going to determined the behaviour of your element. display 属性的值将决定元素的行为。 By default the value is set to inline.默认情况下,该值设置为内联。 In chart JS when you set the display value to false it equals like displaying it to none.在图表 JS 中,当您将显示值设置为 false 时,它等于将其显示为无。 I would also manipulate with canvas height and width as that can have an effect of grouping your elements.我还将使用 canvas 高度和宽度进行操作,因为这可能会产生对元素进行分组的效果。 As you have provided snippet of HTML and CSS it is hard to exactly determined your layout problem.由于您提供了 HTML 和 CSS 的片段,因此很难准确确定您的布局问题。 I hope this helps.我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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