是否可以在g.Raphaël条形图中为每个条形图赋予自己的颜色?
我完全可以改变系列的颜色。 但我想要的是,每个系列的第一个结果是有相似的颜色,每个系列的第二个等等。
我找不到很多关于它的文档,我尝试了一些无头实验,但没有一个能达到我想要的效果。
答案 0 :(得分:3)
您可以设置如下选项:
var custom_colors =["#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff"];
r.barchart(x,y,width,height,[data], { colors: custom_colors });
其他选项
var options : {
legend : [],
stacked: false, //Use this to stack your bars instead of displaying them side by side
type: "soft", //round, sharp, soft, square,
colors : custom_colors
}
r.barchart(x,y,width,height,[data], options);
您可能想要在函数中定义颜色。您可以使用以下功能:
function _getColors() {
var byndColors = ["#ffc000","#1d1d1d","#e81c6e","#7c7c7c","#00aff2","#aaaaaa","#611bc9"];
//some random colors
var randColors = ["#77efac","#364f8a","#60cb94","#cf263b","#2471bb","#7fc398","#d2c66a","#2109dc","#66ad29","#9a9754","#640cdf","#257683","#d51e05","#4bb36e","#e7408a","#1ef173","#1756bc","#cff215","#15c2fb","#f010ab","#844a0","#c34021","#3e4cf2","#8e2864","#a28f5c","#a9d528","#7b1e43","#a5401c","#829813","#691ccd"]
//combine them
return byndColors.concat(randColors);
}
并使用它:
r.barchart(x,y,width,height,[data], { colors: _getColors() });
答案 1 :(得分:1)
您可以在attr
svg
属性
r.barchart(x,y,width,length,[data]);
var colors =["#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#552288","#228844","#a38643","#296583"];
// use jquery for easier way
$("#holder svg path").each(function(index){
$(this).attr("fill",colors[index]);
});
答案 2 :(得分:0)
您需要指定一些颜色,然后确保数据是一个数组数组,其中内部数组的索引对于除索引之外的所有值都是0:
data = [[55, 0, 0], [0, 20, 0], [0, 0, 40]];
r.barchart(10, 10, 100, 220, data, {
colors: [
// Some colours
"000-#d00-#900",
"000-#f64-#c31",
"000-#fc0-#c90",
"000-#3a3-#070",
"000-#2bc-#089",
"000-#00d-#00a",
"000-#808-#404",
"000-#444-#000"
]
});
此处r
是Raphael实例。见http://g.raphaeljs.com/barchart.html