如何解决堆叠的Highchart图无法正确显示0个值
我正在vue应用程序中使用highchart库在图形中显示数据。下面是我所面临的问题的代码片段。问题在于数据系列中,当数据数组的第一个元素包含0值时,它在映射中显示为0,但是如果0在任何其他位置,则对于特定名称它不显示为0。 / p>
series: [{
name: 'John',data: [5,4,2]
},{
name: 'Jane',data: [0,3,1]
},{
name: 'Joe',2,5]
}]
在上述系列数组中,John,Jane和Joe的第一个值分别为5、0、0,第二个值分别为0、0、4。但是在下面的图形中,第一列图形显示为0,第二列图形显示为0。请帮助解决此问题。我也不想在第一栏中显示那个0。
Highcharts.chart('container',{
chart: {
type: 'column'
},title: {
text: 'Stacked column chart'
},xAxis: {
categories: ['Apples','Oranges','Pears','Grapes','Bananas']
},yAxis: {
min: 0,title: {
text: 'Total fruit consumption'
},stackLabels: {
enabled: true,style: {
fontWeight: 'bold',color: ( // theme
Highcharts.defaultOptions.title.style &&
Highcharts.defaultOptions.title.style.color
) || 'gray'
}
}
},legend: {
align: 'right',x: -30,verticalAlign: 'top',y: 25,floating: true,backgroundColor:
Highcharts.defaultOptions.legend.backgroundColor || 'white',borderColor: '#CCC',borderWidth: 1,shadow: false
},tooltip: {
headerFormat: '<b>{point.x}</b><br/>',pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},plotOptions: {
column: {
stacking: 'normal',dataLabels: {
enabled: true
}
}
},series: [{
name: 'John',2]
},{
name: 'Jane',1]
},{
name: 'Joe',5]
}]
});
#container {
height: 400px;
}
.highcharts-figure,.highcharts-data-table table {
min-width: 310px;
max-width: 800px;
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;
}
<script src="https://code.highcharts.com/highcharts.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">
Chart showing stacked columns for comparing quantities. Stacked charts
are often used to visualize data that accumulates to a sum. This chart
is showing data labels for each individual section of the stack.
</p>
</figure>
解决方法
plotOptions: {
column: {
stacking: 'normal',dataLabels: {
enabled: true,formatter: function(){
var val = this.y;
if (val === 0) {
return '';
}
return val;
},}
}
},
这是解决问题的方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。