Javascript 在 Chart.js 中更改 X 和 Y 轴值的颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35383677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 17:39:52  来源:igfitidea点击:

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

javascriptjquerychartschart.js

提问by Mike Barwick

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. I figured the below might do it - but it does nothing to the chart at all.

我正在使用 v2.*。但是,我似乎无法为折线图设置默认颜色。我主要是想设置 x/y 图表值的颜色。我认为下面可能会做到这一点 - 但它对图表根本没有任何作用。

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.

这是一个带有实时图表的 jsfiddle。简而言之,我希望更改标签的颜色,即 2016 年 2 月 7 日等。

https://jsfiddle.net/o534w6jj/

https://jsfiddle.net/o534w6jj/

回答by Mike Barwick

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

好的,所以我想通了。这是ticks我正在寻找的属性...请参阅下面的代码。

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

查看更新的 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,
                },
            }],
        }
    }         
});