首页 文章

标签颜色谷歌饼图

提问于
浏览
1

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

Google图表中有“标签”选项,但我没有看到任何标签名称 .

谢谢,

1 回答

  • 2

    我想我们遇到了同样的问题 . 在我的情况下,我必须在我的谷歌饼图中将分类帐帐号与某些颜色组合在一起 . 因此,在为饼图构建我的数组数据时,我还会创建一个数组颜色 . 在那个循环中我用这个:

    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'],
    

    结果是两个带有链接分类帐帐户和颜色的饼图!希望我已经足够清楚了,如果你对此仍有疑问,请告诉我 .

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

    Two pie charts

相关问题