2016-05-18 224 views
16

我使用chart.js创建条形图,似乎无法更改标签颜色或图例颜色。我想出了如何改变勾号的颜色,但我不确定把'scaleFontColor'放在哪里,如果这确实是我需要使用的。Chart.js标签颜色

下面是它现在的样子的链接。 http://imgur.com/nxaH1mk

这里是我的代码:

var ctx = document.getElementById("myChart"); 
var myChart = new Chart(ctx, { 
    scaleFontColor: "white", 
    type: "bar", 
    data: { 
     labels: <?php echo json_encode($timeSlice); ?>, 
     datasets: [{ 
      label: "A Label", 
      backgroundColor: "rgba(159,170,174,0.8)", 
      borderWidth: 1, 
      hoverBackgroundColor: "rgba(232,105,90,0.8)", 
      hoverBorderColor: "orange", 
      scaleStepWidth: 1, 
      data: <?php echo json_encode($myCount); ?> 
     }] 
    }, 
    options: { 
     legend: { 
      fontColor: "white" 
     }, 
     scales: { 
      yAxes: [{ 
       ticks: { 
        fontColor: "white", 
        stepSize: 1, 
        beginAtZero: true 
       } 
      }] 
     } 
    } 
}); 

任何帮助将不胜感激。

+0

https://stackoverflow.com/a/48580585/7186739 – Super

回答

38

呃我解决了,对这个问题感到抱歉。但我想我会留下一个答案,以防其他人遇到我的问题。

var ctx = document.getElementById("myChart"); 
var myChart = new Chart(ctx, { 
    type: "bar", 
    data: { 
     labels: <?php echo json_encode($timeSlice); ?>, 
     datasets: [{ 
      label: "My Label", 
      backgroundColor: "rgba(159,170,174,0.8)", 
      borderWidth: 1, 
      hoverBackgroundColor: "rgba(232,105,90,0.8)", 
      hoverBorderColor: "orange", 
      scaleStepWidth: 1, 
      data: <?php echo json_encode($myCount); ?> 
     }] 
    }, 
    options: { 
     legend: { 
      labels: { 
       fontColor: "white", 
       fontSize: 18 
      } 
     }, 
     scales: { 
      yAxes: [{ 
       ticks: { 
        fontColor: "white", 
        fontSize: 18, 
        stepSize: 1, 
        beginAtZero: true 
       } 
      }], 
      xAxes: [{ 
       ticks: { 
        fontColor: "white", 
        fontSize: 14, 
        stepSize: 1, 
        beginAtZero: true 
       } 
      }] 
     } 
    } 
}); 
+0

谢谢!帮助了我很多 – molbal

+0

帮助了我。谢谢! –

+0

谢谢,他们确实需要改进他们的文档。 – phil