2017-09-11 36 views
0

我正在一个节点/反应单页面应用程序中加载我的高图数据,我无法弄清楚如何将它居中在页面中间。目前,它看起来像这样:如何在页面上放置highcharts饼图和图例?

enter image description here

它浮在左,我想中心在中间的橙色框的一切。我查看了整个highcharts api文档,似乎无法弄清楚。该的jsfiddle是在这里:http://jsfiddle.net/tobitobetoby/1fqvzpdn/36/(即使它的jsfiddle中心的真实,它漂浮到左边的web/html页面上)

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'/> &nbsp 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(); 
    } 
    } 
} 
+0

无关,但' '在导出时呈现。您可以为图标自身添加正确的填充空间。 –

+0

或者至少应该有结尾分号。 '&nbsp'→' ' –

回答

0

纵观整个混帐回购协议添加这个领域,index.css文件没有被导入在index.js文件,因此不能够引用css命令。解决办法是,在index.js文件中添加:

import './index.css'; 

返回代码顶部。然后在index.css文件中,添加:

.highcharts-container { 
    margin: 0 auto; 
} 

而这将以输入Highcharts div为中心。

0

中心就在div标签。只需将align="center"添加到div即可。这里是你的更新fiddle

0

在你的js函数

legend: { 
    backgroundColor: '#F5F5F5', 
    layout: 'horizontal', 
    floating: true, 
    align: 'center', 
    verticalAlign: 'top' 
} 
+0

当我根据您的建议更新小提琴时,会导致整个网格混乱。 –