Change color of X and Y axis values. Chart.js

2019-02-12 09:45发布

问题:

I'm using v2.*... However, I can't seem to set the default color for a line chart. I'm mainly looking to set the color of the x/y chart values. figured the below might do it - but it does nothing to the chart at all.

Chart.defaults.global.defaultColor = 'orange',

Update: here's a jsfiddle with live chart In short, I'm looking to change the color of the labels i.e. Feb 7, 2016, etc etc.

https://jsfiddle.net/o534w6jj/

Help? :)

回答1:

Okay, so I figured it out. It's the ticks property I'm looking for...see code below.

See updated jsfiddle: https://jsfiddle.net/o534w6jj/1/

var ctx = $("#weekly-clicks-chart");
var weeklyClicksChart = new Chart(ctx, {
    type: 'line',
    data: data,
    scaleFontColor: 'red',
    options: {
            scaleFontColor: 'red',
        responsive: true,
        tooltips: {
            mode: 'single',
        },
        scales: {
            xAxes: [{ 
                gridLines: {
                    display: false,
                },
                ticks: {
                  fontColor: "#CCC", // this here
                },
            }],
            yAxes: [{
                display: false,
                gridLines: {
                    display: false,
                },
            }],
        }
    }         
});