2

我有一个包含两种数据类型的饼图:好的和不好的。我想用绿色渲染好,而不用红色渲染好。我在文档中进行了搜索,但没有结果。到目前为止,我的代码是:

new CanvasXpress("orderProgressCanvas", {
  "y": {
    "vars": [
      "Ok",
      "No"
    ],
    "smps": [
      "Percentuale completamento"
    ],
    "colorRGB": [
      "rgb(0,255,0)",
      "rgb(255,0,0)"
    ],
    "data": [
      [
        progress
      ],
      [
        100-progress
      ]
    ]
  }
}, {
  "graphType": "Pie",
  "pieSegmentPrecision": 1,
  "pieSegmentSeparation": 2,
  "pieSegmentLabels": "outside",
  "pieType": "solid",
  "showLegend": false,
  "background" : "rgb(192,208,216)"
});

但是颜色定义不起作用..有什么想法吗?progress 是一个从 0 到 100 的 JavaScript 变量。

谢谢

4

1 回答 1

2

我问主要开发人员:

只需将您想要的颜色放在配置中的颜色属性中即可。它们将按照您指定的顺序被选中。还要确保指定足够的颜色,否则它们将在使用时被回收。

'colors': ['rgb(234,234,1)', 'rgb(56,35,12)'.......etc]

我的代码变成了:

new CanvasXpress("orderProgressCanvas", {
  "y": {
    "vars": [
      "Ok",
      "No"
    ],
    "smps": [
      "Percentuale completamento"
    ],
    "data": [
      [
        progress
      ],
      [
        100-progress
      ]
    ],
  }
}, {
  "graphType": "Pie",
  "pieSegmentPrecision": 1,
  "pieSegmentSeparation": 2,
  "pieSegmentLabels": "outside",
  "pieType": "solid",
  "showLegend": false,
  "background" : "rgb(192,208,216)",
  "colors": [
           "rgb(57,133,0)",
           "rgb(163,0,8)"
           ],
});
于 2012-10-03T23:29:41.643 回答