highcharts - 如何在highchart的全屏视图中将图表设置在中心
问题描述
我想将此图表设置为在 highchart 中居中。
我尝试将以下代码用于图表
Highcharts.chart('container', {
chart: {
type: 'bar',
height: '300'
},
title: {
text: ''
},
subtitle: {
text: ''
},
xAxis: {
categories: ["category 1","category 2"],
crosshair: true,
gridLineWidth: 0,
title: {
text: null
}
},
yAxis: {
min: 0,
max: 1050,
gridLineWidth: 0,
title: {
text: '',
align: 'high'
},
labels: {
overflow: 'justify',
enabled: false
}
},
tooltip: {
valueSuffix: ' '
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
},
colorByPoint: true,
},
series: {
shadow: true,
marker: {
fillColor: '#FFFFFF',
lineWidth: 1,
lineColor: null,
radius: 4
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 80,
floating: true,
borderWidth: 1,
backgroundColor:
Highcharts.defaultOptions.legend.backgroundColor || '#FFFFFF',
enabled: false
},
credits: {
enabled: false
},
colors: color_codes,
exporting: {
buttons: {
contextButton: {
menuItems: ["viewFullscreen", "printChart",
"downloadPNG",
"downloadJPEG",
"downloadPDF",
"downloadSVG",
"downloadCSV",
"downloadXLS"]
}
}
},
series: [{
name: '',
data: [10,20]
}
]
});
解决方案
您应该能够通过使用该功能并在全屏模式加载时chart.update
更改值来实现它。marginLeft
演示:https ://jsfiddle.net/BlackLabel/y3g7e6s0/
events: {
render() {
const chart = this;
if (chart.fullscreen.isOpen && chart.updateFlag) {
const width = chart.chartWidth;
chart.updateFlag = false;
chart.update({
chart: {
marginLeft: width / 2
}
})
chart.updateFlag = true;
} else if (chart.updateFlag) {
chart.updateFlag = false;
chart.update({
chart: {
marginLeft: initialPlotLeft
}
})
chart.updateFlag = true;
}
},
load() {
initialPlotLeft = this.plotLeft;
}
}
API:https ://api.highcharts.com/highcharts/chart.events.render
API:https ://api.highcharts.com/highcharts/chart.marginLeft
API:https ://api.highcharts.com/class-reference/Highcharts.Chart#update
推荐阅读
- python - 如何通过公共键列(固定长度限制)连接单个熊猫数据框中的多行?
- java - 为用户登录用户弹出 AzureAD 浏览器并输出令牌的 Java 库是什么?
- reactjs - 使用 React Router 创建进度条
- oracle - 如何在postgres中为每个division_id设置前N个值
- cytoscape.js - 如何在父节点之间创建出租车边缘?
- php - 有很多深厚的关系
- html - z-index 不适用于所有图层
- php - 如何修复此 foreach 以使链接适用于每个元素/页面?
- sql - 计算 this.row 与另一个表中的行相关的总行数
- mysql - 使用内部连接 3 个表和 where 子句查询选择