2012-02-28 166 views
0

如何在Google饼图中为标签名称定义指定的颜色? 例如,“Label1”必须始终为红色。 “Label2”绿色。 服务器生成的标签可能会有其他标签,但是这两个标签必须是红色和绿色。其余的应该是不同的颜色。标签颜色Google饼图

Google Charts中有'label'选项,但我没有看到任何标签名称。

谢谢,

回答

2

我认为我们有同样的问题。在我的情况下,我不得不在我的Google饼图中将分类帐帐号与特定颜色结合起来。所以,在构建饼图的阵列数据时,我也创建了一个数组颜色。在这个循环我使用这个:

var list = []; 
    $.each(dataObj.model_Response[0].array, function(key, item) { 
    var row = []; 
    var value = item.account.amount; 
    colors.push(_toColor(item.account.number.toString())); 
    row.push(item.account.name); 
    row.push(value); 
    list.push(row); 
    }); 
    //.. list add to google DataTable. 

的_toColor功能:

var _toColor = function(n) { 
    n = crc32(n); 
    n &= 0xffffffff; 
    return("#" + ("000000" + dechex(n)).substr(-6)); 
} 

在我的选择VAR我可以简单地指定数组:

colors: result['colors'], 

而结果是两个pie-带有链接账户和颜色的图表!希望我已经清楚了,如果你仍然有疑问,请告诉我。

这是我的两个饼状图的结果:

Two pie charts