首页 > 解决方案 > Highcharts 不正确地处理负值

问题描述

我创建了一个JS fiddle,其中百分比面积图表是使用具有一组负值的数据绘制的。

Highcharts.chart('container', {
  "chart": {
    "type": "area",
    "style": {
      "fontFamily": "Arial"
    },
    "width": "800"
  },
  "title": {
    "text": ""
  },
  "credits": {
    "enabled": false,
    "additionalProperties": {}
  },
  "legend": {
    "border": "#333333",
    "borderWidth": 0,
    "borderRadius": 3,
    "itemDistance": 20,
    "itemMarginBottom": 3,
    "margin": 5,
    "padding": 10,
    "align": "center",
    "itemStyle": {
      "fontSize": "10",
      "font-weight": "normal",
      "fontFamily": "Arial"
    },
    "itemWidth": 200
  },
  "subtitle": {
    "text": ""
  },
  "colors": ["#67A262", "#67A262", "#FFC110", "#f77b3f", "#61d3f0"],
  "xAxis": {
    "categories": ["12/11", "4/12", "8/12", "12/12", "4/13", "8/13", "12/13", "4/14", "8/14", "12/14", "4/15", "8/15", "12/15", "4/16", "8/16", "12/16", "4/17", "8/17", "12/17", "4/18", "8/18", "12/18", "4/19", "8/19", "10/19"],
    "tickmarkPlacement": "on",
    "title": {
      "enabled": false
    },
    "labels": {
      "align": "center",
      "style": {
        "fontSize": "10px",
        "font-weight": "normal",
        "fontFamily": "Arial, Helvetica, sans-serif"
      }
    }
  },
  "yAxis": {
    "title": {
      "text": "Percent"
    }
  },
  "tooltip": {
    "pointFormat": "<span style=\"color:{[#67A262, #67A262, #FFC110, #f77b3f, #61d3f0]}\">{series.name}</span>: <b>{point.percentage:.1f}%</b> ({point.y:,.0f} millions)<br/>",
    "shared": true
  },
  "plotOptions": {
    "area": {
      "stacking": "percent",
      "lineColor": "#ffffff",
      "lineWidth": 1,
      "marker": {
        "lineWidth": 0,
        "lineColor": "#ffffff",
        "enabled": false
      }
    }
  },
  "series": [{
    "name": "Cash",
    "data": [0, 0, 3247037, 4115431, 3649666, 5297250, 4956569, 1625115, 3174121, 6694144, 1512948, 3440926, 683988, 889192, 703447, 2515743, 5878442, 5260639, 2247735, 1696123, 6485498, 1514393, 2055804, 1546508, 1421063]
  }, {
    "name": "Fixed Income",
    "data": [0, 0, 1216772, 1659681, 1902223, 1570967, 1314055, 977437, 887057, 1536891, -653674, -1059915, -1339804, -1071393, -998063, -1200418, -1375094, -1438987, 377989, -133323, 7332923, 12508089, 13924871, 15185459, 15145308]
  }, {
    "name": "Equities",
    "data": [0, 0, 2924177, 7939481, 10863595, 12100681, 16650757, 18639670, 20783963, 17146281, 9656794, 6784358, 7574038, 5126567, 5647696, 2539386, 2750490, 3856696, 4627848, 6936117, 22863720, 19581687, 23265765, 21775318, 22517049]
  }, {
    "name": "Alternatives",
    "data": [11729500, 11896355, 12286734, 12043719, 12763997, 11602665, 9505520, 9005992, 9954085, 11116397, 1982778, 3138404, 3767757, 3899267, 3614944, 5307771, 1708839, 889320, 3074970, 840986, 15276520, 15166745, 15090469, 14700818, 14904036]
  }, {
    "name": "Other",
    "data": [482853, 550589, 627809, 813745, 946673, 1017471, 1101900, 1076074, 1254348, 1230801, 1499999, 1500000, 1631191, 2188279, 2188478, 2254838, 2423621, 2422634, 2432769, 2367905, 4647985, 4530435, 22885564, 23693095, 23706588]
  }]
});

在这里,Highcharts 在计算百分比时将负值视为正值。

预期计算:

在此处输入图像描述

实现的计算:

在此处输入图像描述

请帮助我理解实现。

标签: javascriptjqueryhighcharts

解决方案


推荐阅读