我正在将我的 highchart 数据加载到节点/ react 单页应用程序上,但我不知道如何将它置于页面中间。目前它看起来像这样:
它向左浮动,我想将所有内容置于中间的橙色框中。我查看了整个 highcharts api 文档,但似乎无法弄明白。 jsfiddle 在这里:http://jsfiddle.net/tobitobetoby/1fqvzpdn/36/ (即使它在 jsfiddle 中居中,它也会在 web/html 页面上 float 到左侧)
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'pie',
events: {
load: function(event) {
var chart = this,
points = chart.series[0].points,
len = points.length,
total = 0,
i = 0;
for (i = 0; i < len; i++) {
total += points[i].y;
}
chart.setTitle({
text: '<br>€' + total,
verticalAlign: 'middle',
style: {
fontFamily: 'Arial,Roboto,Helvetica,sans-serif',
fontWeight: 'bold',
fontSize: 34
},
});
// Adding 'transaction' label - labels below don't support images/icons
this.renderer.label("<div class='transactions' style='fontSize:20px !important;'><img style='width:25px; height:25px; position:relative; top:7px;' src='https://github.com/tobi-ajala/shell-exercise/blob/master/icons/card.png?raw=true'/>   Transactions</div>", 120, 130, null, null, null, true).add();
// Adding date label
this.renderer.label("<div class='transactions'>11 Sept 2017 - 11 Oct 2017</div>", 95, 225, null, null, null, true).add();
}
}
}
最佳答案
查看完整的 git 仓库,index.css 文件没有导入到 index.js 文件中,因此无法引用 css 命令。解决方法是,在index.js文件中,添加:
import './index.css';
到代码的顶部。然后在index.css文件中,添加:
.highcharts-container {
margin: 0 auto;
}
这将使输入 Highcharts div 居中。
关于javascript - 如何在页面上居中显示 highcharts 饼图和图例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46161312/