在highcharts图表中是否可以有多个副标题(我需要2个)?顺便提一下,我已经有了主标题。
在highcharts图表中是否可以有多个副标题(我需要2个)?顺便提一下,我已经有了主标题。
subtitle: {
text: 'Line 1 of the subtitle<br>Line 2 of the subtitle'
},
http://api.highcharts.com/highcharts#Renderer.text
在这里弄琴: http://jsfiddle.net/flacoman91/bvJaQ/ 移动文本有点繁琐,但它能完成工作。$(function () {
$('#container').highcharts({
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
}, function(chart) { // on complete
var middle = chart.plotSizeX - 100;
chart.renderer.text('Series 1', chart.plotSizeX / 2, 150)
.attr({
})
.css({
color: '#4572A7',
fontSize: '16px'
})
.add();
chart.renderer.text('Subtitle 2', chart.plotSizeX / 2, 300)
.attr({
})
.css({
color: '#4572A7',
fontSize: '16px'
})
.add();
});
});
看起来像是一个错误,所以我已经在这里报告了它:https://github.com/highslide-software/highcharts.com/issues/1704
您可以使用普通的br-html标记在字幕中换行。然后,您可以根据是否换行来设置标题边距。
js
const graphSubtitles = `
<span class="subtitle1">${subtitle1}</span>
<span class="subtitle2">${subtitle2}</span>
`;
const config = {
title: {
align: 'low',
text: 'Title',
},
subtitle: {
align: 'low',
useHTML: true,
text: graphSubtitles,
textAlign: 'left',
},
...
};
Highcharts.chart('container', config);
CSS
subtitle1 {
color: red;
}
subtitle2 {
color: blue;
}