如何在chart.js条形图中更改条形填充颜色

时间:2014-04-09 03:23:07

标签: chart.js

我使用chart.js绘制条形图。如何更改chart.js中的条形填充颜色(我使用'条形图')

var data = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
    {
        fillColor : "rgba(220,220,220,0.5)",
        strokeColor : "rgba(220,220,220,1)",
        data : [65,59,90,81,56,55,40]
    },
    {
        fillColor : "rgba(151,187,205,0.5)",
        strokeColor : "rgba(151,187,205,1)",
        data : [28,48,40,19,96,27,100]
    }
]

}

fillColor:" rgba(220,220,220,0.5)是什么意思?如何更改此颜色?

1 个答案:

答案 0 :(得分:3)

rgba代表红绿蓝alpha。参数如下:

rgba(x, y, z, w)
  • x:红色(0-255)
  • y:绿色(0-255)
  • z:蓝色(0-255)
  • w:alpha值(不透明度)。 1是完全不透明的,0是完全透明的

您还可以将Hex values指定为颜色:

{
    fillColor : "#ffff00",
    strokeColor : "#000000",
    data : [65,59,90,81,56,55,40]
}

或预定义的colour names代替,如果您不想使用rgba值:

{
    fillColor : "yellow",
    strokeColor : "black",
    data : [65,59,90,81,56,55,40]
}