图表js-为每个x轴标签应用不同的颜色 [英] chart js - Apply different color for each x-axes label

查看:72
本文介绍了图表js-为每个x轴标签应用不同的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Chart Js构建的图表。需要为每个标签应用不同的颜色,而不是为所有标签应用相同的颜色。有没有办法在滴答回拨功能中做到这一点。 ?

I have a chart built using Chart Js. Need to apply different color for each label rather than applying same color for all labels. Is there a way to do it in ticks call back function. ?

    scales: {
        xAxes: [{ 
            gridLines: {
                display: false,
            },
            ticks: {
            callback: function(label, index, labels) {
                  if ('Feb 9, 2016' === label) {
                  fontColor: "red"; // Something like this
                   return label+'f';
                } else {
                    return label;
                }
                },
             // fontColor: "red", // this here
            },
        }],
        yAxes: [{
            display: false,
            gridLines: {
                display: false,
            },
        }],
    }


推荐答案

看看此问题,您当前无法在不更改 Chart.js 源代码的情况下完成此操作(尽管很容易解决)

take a look at this issue, you can't currently do it without changing Chart.js source code (easy fix though)

这篇关于图表js-为每个x轴标签应用不同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆