如何在 Highchart 上仅使用 json 对象(无 js 函数)更改系列(分组柱形图)的颜色?

How to change the color of series(grouped column chart) only with json object(without js function) on Highchart?

我实际上使用了一个名为 Jedox 的工具,它允许我使用 Highchart.js 库来制作图表。所以我尝试制作一个包含 2 个系列和 4 列的简单图表,它是一个分组柱形图(簇状条形图)。我在 Highchart 上看到可以使用数组“颜色”更改系列的颜色,但是当我使用它时它不起作用。为什么 ?我也尝试使用 colorByPoint,它正在工作,但它不是我想要的,因为它为类别着色,但在类别中有不同的系列,我希望每个系列都有精确的颜色。我该怎么做?

在您看到代码之前,这里有一些精确性:我将“未定义”放在颜色属性上,因为无法删除这些属性,所以我将它们设为默认值。通常当该值设置为“未定义”时,颜色对应于“颜色”数组中的一种颜色。

在帮助我之前你必须知道的一件重要事情:我不会使用 JS,我只能使用 JSON 仅此而已。

这是我的代码:(它只是一个 json)

"chart": {
    "type": "column",
    "zoomType": "xy",
    "borderRadius": 0,
    "events": {},
    "height": 300,
    "width": 400,
    "backgroundColor": "#FFFFFF",
    "borderWidth": 1,
    "borderColor": "#D8D8D8",
    "plotBackgroundColor": null,
    "plotBorderWidth": 0,
    "plotBorderColor": "#000100",
    "spacingTop": 20
  },
  "plotOptions": {
    "series": {
      "minPointLength": 1,
      "dataLabels": {
        "enabled": false,
        "inside": false,
        "rotation": 0,
        "x": 0,
        "y": 0,
        "style": {
          "fontFamily": "Arial",
          "fontSize": 9,
          "color": "#366092",
          "fontWeight": "normal",
          "fontStyle": "regular"
        }
      },
      "cursor": null,
      "point": {
        "events": {}
      }
    }
  },
  "legend": {
    "symbolRadius": 0,
    "backgroundColor": null,
    "borderWidth": 0,
    "borderColor": "#000100",
    "itemStyle": {
      "fontFamily": "Arial",
      "fontWeight": "normal",
      "fontSize": "11px",
      "color": "#445862",
      "fontStyle": ""
    },
    "floating": false,
    "align": "center",
    "verticalAlign": "bottom",
    "layout": "horizontal",
    "reversed": false
  },
  "title": {
    "text": null
  },
  "series": [
    {
      "name": "Expected",
      "data": [
        1,
        5
      ],
      "color": "undefined",
      "id": 0,
      "property": "dcColumnClustered",
      "type": "column",
      "yAxis": 0,
      "zIndex": 2,
      "borderWidth": 0,
      "dataLabels": {
        "enabled": false
      }
    },
    {
      "name": "Current",
      "data": [
        2,
        3
      ],
      "color": "undefined",
      "id": 1,
      "property": "dcColumnClustered",
      "type": "column",
      "yAxis": 0,
      "zIndex": 2,
      "borderWidth": 0,
      "dataLabels": {
        "enabled": false
      }
    }
  ],
  "xAxis": [
    {
      "id": "x_0",
      "axtype": "xAxis",
      "labels": {
        "enabled": true,
        "style": {
          "fontFamily": "Arial",
          "fontWeight": "normal",
          "fontSize": "11px",
          "color": "#445862",
          "fontStyle": ""
        },
        "autoRotation": false
      },
      "categories": [
        "col1",
        "col2"
      ],
      "title": {
        "style": {
          "fontFamily": "Arial",
          "fontWeight": "normal",
          "fontSize": "11px",
          "color": "#445862",
          "fontStyle": ""
        },
        "text": ""
      },
      "tickInterval": null,
      "minorTickInterval": null,
      "gridLineWidth": 0,
      "minorGridLineWidth": 0,
      "reversed": false,
      "reversedStacks": false
    }
  ],
  "yAxis": [
    {
      "id": "y_0",
      "axtype": "yAxis",
      "opposite": false,
      "labels": {
        "enabled": true,
        "style": {
          "fontFamily": "Arial",
          "fontWeight": "normal",
          "fontSize": "11px",
          "color": "#445862",
          "fontStyle": ""
        },
        "autoRotation": false
      },
      "gridLineWidth": 1,
      "gridLineColor": "#D8D8D8",
      "title": {
        "text": "",
        "style": {
          "fontFamily": "Arial",
          "fontWeight": "normal",
          "fontSize": "11px",
          "color": "#445862",
          "fontStyle": ""
        }
      },
      "tickInterval": null,
      "minorTickInterval": null,
      "reversed": false,
      "reversedStacks": true
    }
  ],
  "tooltip": {
    "enabled": true
  },
  "colors": [
    "#FF0000",
    "#0000FF"
  ]

这是my Fiddle 这是 goal I want to reach

默认颜色值为 undefined,而不是字符串 "undefined"。 (如果 Jedox 不允许未定义的值,请改为 null

    "series": [{
            "color": undefined,
            ...
        },
        {
            "color": undefined,
            ...
        }
    ]

现场演示: https://jsfiddle.net/BlackLabel/zocj5a0b/

API参考:https://api.highcharts.com/highcharts/series.column.color