Highcharts文字云,我需要正确显示图表数据表

时间:2019-05-06 18:59:34

标签: javascript highcharts

我有一个Highcharts的词云。此处已经为图表显示了表格。但是,代替名称和权重的是其显示类别和广告中的出现次数。在这里我需要在表格标题中显示名称和权重。任何人都可以帮我。这是下面的代码。

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/wordcloud.js"></script>
<div class="chart-outer">
    <div id="container"></div>
    <!-- data table is inserted here -->
</div>
<script src="https://code.highcharts.com/modules/exporting.js"></script><!-- at bottom -->
<script src="https://code.highcharts.com/modules/export-data.js"></script><!-- at bottom -->

脚本

var data = [{
    name: 'Lorem',
    weight: 100
}, {
    name: 'Ipsum',
    weight: 50
}, {
    name: 'Dolor',
    weight: 41
}];

Highcharts.chart('container', {
    series: [{
        type: 'wordcloud',
        data: data,
        name: 'Occurrences'
    }],

    exporting: {
        showTable: true
    }
});

1 个答案:

答案 0 :(得分:0)

对我来说,您要完成的工作并不明显,但我认为您想将表标题分别从“类别”和“出现次数”替换为“名称”和“重量”。

如果是这样,此配置可能对您有用:JSFiddle

 exporting: {
    showTable: true,
    tableCaption: 'Data table',
    csv: {
      // This function is called for each column header.
      columnHeaderFormatter: function (item, key) {
        if (!item || item instanceof Highcharts.Axis) {
          return 'Name';
        }
        // Item is not axis, now we are working with series.
        return 'Weight';
      }
    }
  }