如果标签不适合树状图表Highcharts的div,则应将其换行到第二行

问题描述 投票:0回答:1

JS Fiddle link

Highcharts.chart('container',{

series: [{
        useHTML:true,
    type: 'treemap',
    layoutAlgorithm: 'squarified',
    data: [{
        name: 'A',
        value: 6,
        colorValue: 1
    }, {
        name: 'B',
        value: 6,
        colorValue: 2
    }, {
        name: 'C',
        value: 4,
        colorValue: 3
    }, 
    {
        name: 'Gnscweoihciohoihrioghoierhgoierhoiehgoirehgoirehoih',
        value: 1,
        colorValue: 7
    }]
}],
title: {
    text: 'Highcharts Treemap'
}

});

我尝试使用HTML:true属性,但没有帮助。 Word-Break也未得到应用

javascript jquery css highcharts treemap
1个回答
0
投票

需要进行2次更新:

1。您必须在dataLabels属性中添加series属性

您在useHTML: ture之外添加了dataLabels属性,所以请像下面这样使用:

dataLabels: {
    useHTML: true,
    formatter() {
        return '<div>'+this.point.name+'</div>';
    }
},

2。为数据标签添加css

.highcharts-data-label span {
    white-space: normal !important;
}

检查您的代码内容中的工作示例:

Highcharts.chart('container', {
    series: [{
        dataLabels: {
            useHTML: true,
            formatter() {
                return '<div>'+this.point.name+'</div>';
            }
        },
        type: 'treemap',
        layoutAlgorithm: 'squarified',
        data: [{
            name: 'A',
            label: "A",
            value: 6,
            colorValue: 1
        }, {
            name: 'B',
            value: 6,
            colorValue: 2
        }, {
            name: 'C',
            value: 4,
            colorValue: 3
        }, {
            name: 'D',
            value: 3,
            colorValue: 4
        }, {
            name: 'E',
            value: 2,
            colorValue: 5
        }, {
            name: 'F',
            value: 2,
            colorValue: 6
        }, {
            name: 'This is demo of my code, are you happy',
            value: 1,
            colorValue: 7
        }]
    }],
    title: {
        text: 'Highcharts Treemap'
    }
});
.highcharts-figure,
.highcharts-data-table table {
  min-width: 320px;
  max-width: 700px;
  margin: 1em auto;
}

. .highcharts-data-table table {
  font-family: Verdana, sans-serif;
  border-collapse: collapse;
  border: 1px solid #EBEBEB;
  margin: 10px auto;
  text-align: center;
  width: 100%;
  max-width: 500px;
}

.highcharts-data-table caption {
  padding: 1em 0;
  font-size: 1.2em;
  color: #555;
}

.highcharts-data-table th {
  font-weight: 600;
  padding: 0.5em;
}

.highcharts-data-table td,
.highcharts-data-table th,
.highcharts-data-table caption {
  padding: 0.5em;
}

.highcharts-data-table thead tr,
.highcharts-data-table tr:nth-child(even) {
  background: #f8f8f8;
}

.highcharts-data-table tr:hover {
  background: #f1f7ff;
}

.highcharts-data-label span {
    white-space: normal !important;
}
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/heatmap.js"></script>
<script src="https://code.highcharts.com/modules/treemap.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

<figure class="highcharts-figure">
    <div id="container"></div>
    <p class="highcharts-description">
        Tree maps are great tools for comparing values that are part
        of a whole, or for showing hierarchical data. This example
        is a simple tree map with no hierarchy, showing the value
        differences with rectangle sizes and using a color axis.
    </p>
</figure>

注意: 请不要使用示例中使用的大字“ Gnscweoihciohoihrioghoierhgoierhoiehgoirehgoirehoih”,使用有意义的真实词,这样您将获得更好的解决方案和输出!

© www.soinside.com 2019 - 2024. All rights reserved.