首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何仅用json对象(没有js函数)更改高海图上的系列(分组列图)的颜色?

如何仅用json对象(没有js函数)更改高海图上的系列(分组列图)的颜色?
EN

Stack Overflow用户
提问于 2021-03-15 12:43:45
回答 1查看 233关注 0票数 0

实际上,我使用了一个名为Jedox的工具,它允许我使用Highchart.js库制作图表。所以我试着用2列和4列制作一个简单的图表,它是一个分组列图(聚集条形图)。我在高海图上看到,可以用数组“颜色”改变一个系列的颜色,但是当我使用它时,它没有工作。为什么?我还试着使用colorByPoint,它可以工作,但不是我想要的,因为它为猫系列着色,但是在类别中有不同的系列,我希望每个系列都有一个精确的颜色。我怎么能这么做?

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

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

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

代码语言:javascript
复制
"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"
  ]

这是我的宝贝,这是我想达到的目标

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-15 13:16:16

默认颜色值是undefined,而不是字符串"undefined"。(如果Jedox不允许使用未定义的值,则使用null )

代码语言:javascript
复制
    "series": [{
            "color": undefined,
            ...
        },
        {
            "color": undefined,
            ...
        }
    ]

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66638260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档