我希望填补饼图两侧的空间,我想添加一些额外的叙述来解释图表上的信息..
我知道我可以缩小图表的宽度,并在图表外添加叙述。
这是我到目前为止生成饼图的代码
$('.companyName').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: true,
type: 'pie'
},
title: {
text: 'Division'
},
subtitle: {
text: 'Quarter 1 (0/17/2015 - 10/23/2015)'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 40,
floating: true,
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
showInLegend: true,
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
},
connectorColor: 'silver'
}
}
},
series: [{
type: 'pie',
name: '',
data: [
['Department 1', 334]
,['Department 2', 224]
,['Department 3', 105]
,['Department 4', 19]
,['Department 5', 1]
]
}]
});
答案 0 :(得分:1)
要将其他元素放入Highcharts图表,您可以使用Renderer并添加例如text或label。
$(function () {
$('#companyName').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: true,
type: 'pie'
},
title: {
text: 'Division'
},
subtitle: {
text: 'Quarter 1 (0/17/2015 - 10/23/2015)'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 40,
floating: true,
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
showInLegend: true,
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
},
connectorColor: 'silver'
}
}
},
series: [{
type: 'pie',
name: '',
data: [
['Department 1', 334],
['Department 2', 224],
['Department 3', 105],
['Department 4', 19],
['Department 5', 1]
]
}]
}, function (chart) { // on complete
chart.renderer.label('Adding narrative to<br> pie chart (highcharts)', 250, 200, null, 100, 100)
.css({
color: '#FFFFFF'
})
.attr({
fill: 'rgba(0, 0, 0, 0.75)',
padding: 8,
r: 5,
zIndex: 6
})
.add();
});
});
JSFiddle:http://jsfiddle.net/mxrwztaz/