如何在Highcharts中增加权重值小于5的wordcloud的权重

时间:2019-05-02 16:41:46

标签: javascript html highcharts

我在highcharts中有一个wordcloud,在这里我需要动态更改小于5的权重以正确显示每个单词。在这里,我的最大权重为100,其他权重为5,2,1,因此权重较少无法正确显示。 这是下面的代码。

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
  <script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/wordcloud.js"></script>
<div id="container"></div>

脚本

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

    Highcharts.chart('container', {
        series: [{
            type: 'wordcloud',
            data: data,
            name: 'Occurrences'
        }],
        title: {
            text: 'Wordcloud of Lorem Ipsum'
        }
    });

1 个答案:

答案 0 :(得分:0)

您可以预处理数据并在某些点上增加weight值:

 data.forEach(function(el) {
     if (el.weight < 5) {
         el.weight *= 10;
     }
 });

实时演示: https://jsfiddle.net/BlackLabel/mun80gbo/