简体   繁体   English

HighCharts列上的多个系列数据

[英]Multiple series data on HighCharts column

I'm using HighCharts on a project, and I'm having trouble formatting the data in the way I'd like. 我在一个项目上使用了HighCharts,但在以我想要的方式格式化数据时遇到了麻烦。 I currently have something that works, but it doesn't feel quite right. 我目前有一些有效的方法,但是感觉不太正确。

What I have is a column chart with everything in one series. 我所拥有的是一个柱形图,其中包含一系列内容。 I'd rather have each data point be in it's own series & properly labeled in the legend & tooltips. 我希望每个数据点都属于自己的系列,并在图例和工具提示中正确标记。 Below are samples of the relevant bits to format the data. 以下是用于格式化数据的相关位的示例。

I'm not sure what I'm doing wrong, the changes I've made feel like they should work given their docs & this demo . 我不确定自己在做错什么,我所做的更改让他们觉得应该根据自己的文档此演示进行工作 Also, Do I need the categories if multiple series works? 另外,如果多个系列都可以使用,我是否需要类别?

Working: 工作方式:

"series": [
    {
      "data": [
        {
          "y": 92,
          "name": "Apples: 92ms for 83,481,430 requests",
          "color": "#91cb73"
        },
        {
          "y": 761,
          "name": "Bananas: 761ms for 58,050,877 requests",
          "color": "#ab7053"
        },
        {
          "y": 774,
          "name": "Kiwis: 774ms for 362,294 requests",
          "color": "#44719c"
        }
      ]
   }
]

Demo: http://jsfiddle.net/b65kp/ 演示: http//jsfiddle.net/b65kp/


Not working: 无法运作:

 "series": [
    {
      "name": "Apples",
      "data": {
        "y": 92,
        "name": "92ms for 83,481,430 requests",
        "color": "#91cb73"
      }
    },
    {
      "name": "Bananas",
      "data": {
        "y": 761,
        "name": "761ms for 58,050,877 requests",
        "color": "#ab7053"
      }
    },
    {
      "name": "Kiwis",
      "data": {
        "y": 774,
        "name": "774ms for 362,294 requests",
        "color": "#44719c"
      }
    }
]

Demo: http://jsfiddle.net/u74Qw/1/ 演示: http//jsfiddle.net/u74Qw/1/

The problem is that "data" expects an array, and you are giving it an object. 问题是"data"需要一个数组,而您给它一个对象。 Wrap each object in an array. 将每个对象包装在数组中。 For example: 例如:

"data": [{
        "y": 92,
        "name": "92ms for 83,481,430 requests",
        "color": "#91cb73"
 }]

Here is your full fix , but it might not give the result you expect, personally I like your first attempt better 这是您的完整解决方案 ,但可能无法达到预期的效果,就我个人而言,我更喜欢您的第一次尝试

FWIW, alternate approach to setting this up : FWIW,另一种setting this up方法:

http://jsfiddle.net/jlbriggs/zbW4D/ http://jsfiddle.net/jlbriggs/zbW4D/

Things to consider: 注意事项:

1) using a legend instead of just directly labeling each bar makes the user do a lot of looking back and forth to see which is which (doing both just adds extra clutter to distract the user) 1)使用图例,而不是直接标记每个条形图,使用户来回查看很多东西,看看哪个是哪个(两者都只会增加额外的混乱以分散用户注意力)

2) rotating labels always adds more work for the user 2)旋转标签总是为用户增加工作量

3) multiple colors for the bars is not necessary when each bar is labeled appropriately, and again just adds distraction 3)在适当标记每个条形时,不必为条形使用多种颜色,这只会增加干扰

A horizontal bar chart with no legend and single color for data solves these problems. 没有图例和数据单色的水平条形图解决了这些问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM