Reputation: 265
Is it possible to give each bar its own color in a g.Raphaël bar chart?
I'm fully able to change the color for the series. But what I would like, is the first results of each series to have similar colors, the second of each series and so on.
I can't find much documentation about it, and I've tried a few headless experiments, but none have the effect I want.
Upvotes: 0
Views: 1935
Reputation: 20431
You need to specify some colours and then make sure that data is an array of arrays where the index of the inner arrays are all 0 for all values but that index:
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"
]
});
Here r
is the Raphael instance. See http://g.raphaeljs.com/barchart.html
Upvotes: 0
Reputation: 11
You can change the attr
property of each path in 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]);
});
Upvotes: 1
Reputation: 6411
You can set options like this:
var custom_colors =["#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff"];
r.barchart(x,y,width,height,[data], { colors: custom_colors });
Other options
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);
You might want to define your colors in a function. Here is a function you can use:
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);
}
and use it like:
r.barchart(x,y,width,height,[data], { colors: _getColors() });
Upvotes: 3