ChartJS-PieChart的标签过长并隐藏了PieChart

时间:2019-10-10 04:00:29

标签: javascript php jquery codeigniter chart.js

enter image description here

我有很多来自数据库的数据要显示在标签表上,但是如果饼图在其他显示设备上,则该饼图将被隐藏。我怎么解决这个问题?这是我的代码:

var pieData={
    labels:["A","B","C"],
    datasets:[
    {
        label: [1,2,3] ,
        data:[1,2,3],
        backgroundColor: 
        [
            "#2fb4ed",
            "#ba68c8",
            "#33e0ff",
            "#0fe07f",
            "#ffb74d",
            "#4caf50",
            "#ff7043"
        ]
    }]
};

var pieOption = { legend:{ onClick: null}, 
                  responsive: true, 
                  label: true, 
                  tooltips: 
                  {
                      callbacks: {
                          label: function(tooltipItem, data) {
                              var dataset = data.datasets[tooltipItem.datasetIndex];
                              var total = dataset.data.reduce(function(previousValue, currentValue, currentIndex, array) {return previousValue + currentValue;});
                              var currentValue = dataset.data[tooltipItem.index];
                              var amt = dataset.label[tooltipItem.index];
                              amt = amt.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                              var precentage = Math.floor(((currentValue/total) * 100)+0.5);         
                              return "Amount :" + amt;
                      }
                  }
              }, 

1 个答案:

答案 0 :(得分:0)

根据您不同的响应大小,将参数width和height与动态值一起使用。 示例<Line data={pieData} height="50" width="100" />