Chart.js legend took up too much spaces

后端 未结 5 2034
执笔经年
执笔经年 2020-12-10 15:27

I was having some problem with chart.js legend. The legend with long text took up too much spaces which resulting in the reduce in the size of my pie chart:

Another

5条回答
  •  被撕碎了的回忆
    2020-12-10 15:45

    First off, set canvas­'s width and height using it­'s native attributes (do not use style attribute), like so :

    
    

    note: width should be twice the height

    Then, set responsive property to false in your chart options, as such :

    options: {
       responsive: false,
       ...
    }
    

    ᴅᴇᴍᴏ

    var chart = new Chart(brandChart, {
       type: 'doughnut',
       data: {
          labels: ['Etronin Home Appliances Service & trading Pte Ltd', 'Giant'],
          datasets: [{
             data: [30, 70],
             backgroundColor: ['#2196f3', '#4caf50']
          }]
       },
       options: {
          responsive: false,
          legend: {
             display: true,
             position: 'right',
             onClick: null
          },
       }
    });
    
    

提交回复
热议问题