[英]How to make rectangular legend in highcharts?
Could you please tell me how to make rectangular legend in highcharts?你能告诉我如何在highcharts中制作矩形图例吗?
Currently in my demo legend is circular
or circle
.目前在我的演示传说是
circular
或circle
。 Here is my code http://jsfiddle.net/oupmgvjy/12/这是我的代码http://jsfiddle.net/oupmgvjy/12/
I want to make like this as show in image:我想像这样如图所示:
$(function() {
$('#container').highcharts({
chart: {
type: 'pie'
},
credits: {
enabled: false
},
exporting: { enabled: false },
legend: {
align: 'right',
verticalAlign: 'top',
layout: 'vertical',
x: 0,
y: 100,
labelFormatter: function() {
return '<span style="color:' + this.color + ';background:red!important">' + this.name + ':</span> <b>' + this.y + '</b> </n>';
}
},
yAxis: {
title: {
text: 'Total percent market share'
}
},
plotOptions: {
pie: {
series: {
states: {
hover: {
enabled: false
}
}
},
allowPointSelect: false,
cursor: 'pointer',
showInLegend: true,
dataLabels: {
format: '<b>{point.y}</b>',
style: {
fontWeight: 'bold',
color: 'white'
}
},
startAngle: 0,
endAngle: 270,
center: ['50%', '75%']
}
},
tooltip: {
enabled: false,
shadow: false
},
series: [{
states: {hover: {enabled: false}},
showInLegend: false,
name: 'election result',
enabled: true,
dataLabels: {
enabled: true
},
data: [
['A', 55],
['B', 65],
],
size: '30%',
innerSize: '70%',
}, {
states: {hover: {enabled: false}},
name: 'Versions',
data: [
['sdsd', 55],
['sdf', 65],
['sdf', 65],
['sdf', 132],
],
size: '70%',
innerSize: '80%',
}]
});
});
Try with useHTML and labelFormatter尝试使用 useHTML 和 labelFormatter
legend: {
symbolHeight: 1,
symbolWidth: 1,
symbolRadius: 0,
useHTML:true,
align: 'right',
verticalAlign: 'top',
itemWidth:100,
layout: 'vertical',
x: 0,
y: 100,
labelFormatter: function() {
return '<div style="padding:10px;width:55px;background-color:'+this.color+'"><span style="color: #ffffff;">' + this.name + ': <b>' + this.y + '</b> </span></div> </n>';
}
}
fiddle : http://jsfiddle.net/qhq2ctqr/小提琴: http : //jsfiddle.net/qhq2ctqr/
$(function() { $('#container').highcharts({ chart: { type: 'pie' }, credits: { enabled: false }, exporting: { enabled: false }, legend: { symbolHeight: 1, symbolWidth: 1, symbolRadius: 0, useHTML:true, align: 'right', verticalAlign: 'top', itemWidth:100, layout: 'vertical', x: 0, y: 100, labelFormatter: function() { return '<div style="padding:10px;width:55px;background-color:'+this.color+'"><span style="color: #ffffff;">' + this.name + ': <b>' + this.y + '</b> </span></div> </n>'; } }, yAxis: { title: { text: 'Total percent market share' } }, plotOptions: { pie: { series: { states: { hover: { enabled: false } } }, allowPointSelect: false, cursor: 'pointer', showInLegend: true, dataLabels: { format: '<b>{point.y}</b>', style: { fontWeight: 'bold', color: 'white' } }, startAngle: 0, endAngle: 270, center: ['50%', '75%'] } }, tooltip: { enabled: false, shadow: false }, series: [{ states: {hover: {enabled: false}}, showInLegend: false, name: 'election result', enabled: true, dataLabels: { enabled: true }, data: [ ['A', 55], ['B', 65], ], size: '30%', innerSize: '70%', }, { states: {hover: {enabled: false}}, name: 'Versions', data: [ ['sdsd', 55], ['sdf', 65], ['sdf', 65], ['sdf', 132], ], size: '70%', innerSize: '80%', }] }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <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; max-width: 600px; margin: 0px auto"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.