Chart.js and long labels

前端 未结 6 671
难免孤独
难免孤独 2020-12-30 22:45

I use Chart.js to display a Radar Chart. My problem is that some labels are very long : the chart can\'t be display or it appears very small.

So, is there a way to b

6条回答
  •  情深已故
    2020-12-30 23:04

    It seems you might be actually be talking about data labels and not the scale labels. In this case you'd want to use the pointLabelFontSize option. See below example:

    var ctx = $("#myChart").get(0).getContext("2d");
    
    var data = {
      labels: ["Eating", "Sleeping", "Coding"],
      datasets: [
        {
            label: "First",
            strokeColor: "#f00",
            pointColor: "#f00",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "#ccc",
            data: [45, 59, 90]
        },
        {
            label: "Second",
            strokeColor: "#00f",
            pointColor: "#00f",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "#ccc",
            data: [68, 48, 40]
        }
      ]
    };
    
    // This is the important part
    var options = {
      pointLabelFontSize : 20
    };
    
    var myRadarChart = new Chart(ctx).Radar(data, options);
    

    Finally you may want to play with the dimensions of your < canvas > element as I've found sometimes giving the Radar chart more height helps the auto scaling of everything.

提交回复
热议问题