javascript Chart.js 文本颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28546677/
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-10-28 09:09:38  来源:igfitidea点击:

Chart.js Text color

javascriptchart.js

提问by downrep_nation

So im using chart.js http://www.chartjs.org/docs/and i cant change the color of the text in the bottom

所以我使用chart.js http://www.chartjs.org/docs/我不能改变底部文本的颜色

ex: "January","February","March","April","May","June","July" and the numbers in the left side

例如:“January”、“February”、“March”、“April”、“May”、“June”、“July”以及左侧的数字

i tried all these options: scaleFontColor: "#FFFFFF" pointLabelFontColor : "#FFFFFF"

我尝试了所有这些选项: scaleFontColor: "#FFFFFF" pointLabelFontColor : "#FFFFFF"

my full code:

我的完整代码:

<script>
    var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
    var lineChartData = {
        labels : ["January","February","March","April","May","June","July"],
        datasets : [
            {
                label: "My Second dataset",
                fillColor : "rgba(255, 89, 114, 0.6)",
                strokeColor : "rgba(51, 51, 51, 1)",
                pointColor : "rgba(255, 89, 114, 1)",
                pointStrokeColor : "#fff",
                pointHighlightFill : "#fff",
                pointHighlightStroke : "rgba(151,187,205,1)",
                maintainAspectRatio: false,
                scaleFontColor: "#FFFFFF",
                pointLabelFontColor : "#FFFFFF",
                pointLabelFontSize : 30,
                data : [1,2,10,7,3,1]
            }
        ]

    }

window.onload = function(){
    var ctx = document.getElementById("canvas").getContext("2d");

    window.myLine = new Chart(ctx).Line(lineChartData, {
        responsive: true
    });
}


</script>

采纳答案by Kenan

scaleFontColoris used to change the color of the labels.

scaleFontColor用于更改标签的颜色。

Instead of putting it in your datasets you should add it as a parameter in your function, like this:

您应该将其作为参数添加到函数中,而不是将其放入数据集中,如下所示:

window.myLine = new Chart(ctx).Line(lineChartData, {
    responsive: true, scaleFontColor: "#FFFFFF" }
});

回答by HitEmUp

The working code ist this:

工作代码是这样的:

Chart.defaults.global.defaultFontColor = "#fff";

Have fun :)

玩得开心 :)

回答by downrep_nation

i found the issue together with Kenan

我和凯南一起发现了这个问题

<script>
    var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
    var lineChartData = {
        labels : ["January","February","March","April","May","June","July"],
        datasets : [
            {
                label: "My Second dataset",
                fillColor : "rgba(255, 89, 114, 0.6)",
                strokeColor : "rgba(51, 51, 51, 1)",
                pointColor : "rgba(255, 89, 114, 1)",
                pointStrokeColor : "#fff",
                pointHighlightFill : "#fff",
                pointHighlightStroke : "rgba(151,187,205,1)",
                maintainAspectRatio: false,
                data : [1,2,10,7,3,1]
            }
        ]

    }

    window.onload = function(){
    var ctx = document.getElementById("canvas").getContext("2d");

    window.myLine = new Chart(ctx).Line(lineChartData, {
        responsive: true, scaleFontColor: "#FFFFFF" }
)};
</script>

it wasnt a normal datatype and i had to adjust the brackets properly!

它不是正常的数据类型,我必须正确调整括号!

thanks alot,looks great now.

非常感谢,现在看起来很棒。