单击高图表中的图表堆栈区域时如何获取类别名称?

时间:2017-08-31 07:53:57

标签: javascript charts highcharts

当点击图表的相关区域时,我需要获得类别名称(年龄> 90天,年龄<90天,年龄<60天,年龄<30天,年龄<14天,年龄<7天)。

例如,当我点击红色区域时,它想要提醒“年龄> 90天”

Graph Image is here!!!

这是我的Hi图表代码。

Highcharts.chart('ageContainer', {
chart: {
    type: 'area',
},
colors: ['#39AA59', '#CEAE22', '#3E90BC','#B787E6','#ea780e','#F85858'].reverse(),
title: {
    text: 'Age of queued patches during the last year'
},
xAxis: {
    categories: lastMonthsName,
    tickmarkPlacement: 'on',
    title: {
        enabled: false
    }
},
yAxis: {
    title: {
        text: 'Patch count'
    },
    labels: {
        formatter: function () {
            return this.value;
        }
    }
},
tooltip: {
    split: true,
    valueSuffix: ' patches'
},
plotOptions: {
    area: {
        stacking: 'normal',
        lineColor: '#666666',
        lineWidth: 1,
        marker: {
            lineWidth: 1,
            lineColor: '#666666'
        }
    }
},
series: [{
    name: 'Age > 90 Days',
    data: getData[5]
},{
    name: 'Age < 90 Days',
    data: getData[4]
},{
    name: 'Age < 60 Days',
    data: getData[3]
},{
    name: 'Age < 30 Days',
    data: getData[2]
},{
    name: 'Age < 14 Days',
    data: getData[1]
},{
    name: 'Age < 7 Days',
    data: getData[0]
}]});

1 个答案:

答案 0 :(得分:0)

查看plotOptions.area.events.click了解详情。另请参阅plotOptions.area.trackByArea。您的帖子不包含实例。使用官方示例来提供解决方案。希望这有帮助

&#13;
&#13;
Highcharts.chart('container', {
  chart: {
    type: 'area'
  },
  title: {
    text: 'Historic and Estimated Worldwide Population Growth by Region'
  },
  subtitle: {
    text: 'Source: Wikipedia.org'
  },
  xAxis: {
    categories: ['1750', '1800', '1850', '1900', '1950', '1999', '2050'],
    tickmarkPlacement: 'on',
    title: {
      enabled: false
    }
  },
  yAxis: {
    title: {
      text: 'Billions'
    },
    labels: {
      formatter: function() {
        return this.value / 1000;
      }
    }
  },
  tooltip: {
    split: true,
    valueSuffix: ' millions'
  },
  plotOptions: {
    area: {
      stacking: 'normal',
      lineColor: '#666666',
      lineWidth: 1,
      marker: {
        lineWidth: 1,
        lineColor: '#666666'
      }
    },
    series: {
      cursor: 'pointer',
      trackByArea: true,
      stickyTracking: false,
      events: {
        click: function(event) {
          alert(this.name)
        }
      }
    }
  },
  series: [{
    name: 'Asia',
    data: [502, 635, 809, 947, 1402, 3634, 5268]
  }, {
    name: 'Africa',
    data: [106, 107, 111, 133, 221, 767, 1766]
  }, {
    name: 'Europe',
    data: [163, 203, 276, 408, 547, 729, 628]
  }, {
    name: 'America',
    data: [18, 31, 54, 156, 339, 818, 1201]
  }, {
    name: 'Oceania',
    data: [2, 2, 2, 6, 13, 30, 46]
  }]
});
&#13;
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
&#13;
&#13;
&#13;