javascript - 如何使用highcharts绘制堆积柱形图?-LMLPHP [[“ isis”,14823424,1012],[“ isis”,7589888,1011],[“ isis_uv”,458752,1115],[“ bgp”,524066816,1059],[“ bgp_policy_reg_agent”,352256 ,146],[“ isis”,7655424,1013],[“ isis_policy_reg_agent”,290816,314]]

Here [0] index is the x-axis
     [1] index is the y-axix
     [2] index is the legend value


我想画一个像这样的图

JSFiddle Link

请引导我绘制它。

最佳答案

Mike Zavarello详细描述了您的问题。

如果您无法(或不想)格式化数据,则下面的功能将为您完成此操作。

chart: {
    type: 'column',
    events: {
      load: function() {
        var chart = this,
          categories = [],
          series = [];
        data.forEach(function(elem) {
          if (!categories.includes(elem[0])) {
            categories.push(elem[0])
          }
        })
        data.forEach(function(elemData) {
          series.push({
            name: elemData[2],
            data: (function() {
              var dataPoints = [];
              categories.forEach(function() {
                dataPoints.push(0)
              })
              categories.forEach(function(elemCategories, j) {
                if (elemCategories == elemData[0]) {
                  dataPoints[j] = elemData[1]
                }
              })
              return dataPoints
            })()
          })
        })
        chart.update({
          series: series,
          xAxis: {
            categories: categories
          }
        }, true, true)
      }
    }
  },


您可以在此处查看示例:https://jsfiddle.net/BlackLabel/mqotyc64/

关于javascript - 如何使用highcharts绘制堆积柱形图?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51286509/

10-14 06:24