2011-09-07 104 views
0

是否可以在g.Raphaël条形图中为每个条打上自己的颜色?g.raphael条形图为每个酒吧不同的颜色?

我完全能够改变系列的颜色。 但我想要的是,每个系列的第一个结果具有相似的颜色,每个系列的第二个等等。

我找不到很多关于它的文档,我已经尝试了几个无头实验,但没有一个能够达到我想要的效果。

+1

您可以使用当前的尝试发布一些代码,可能是[JSFiddle](http://jsfiddle.net/)吗?你应该可以做到这一点,但是要把它们放在一起需要一些努力。 – ghayes

回答

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]); 
}); 
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() }); 
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是圣拉斐尔实例。请参阅http://g.raphaeljs.com/barchart.html

相关问题