简体   繁体   English

如何最大限度地减少百度echarts周围的空白

[英]How to minimize whitespace around Baidu's echarts

I'm trying to incorporate Baidu's echarts (which look really good). 我正在尝试整合百度的echarts(看起来非常好)。 However, there is a lot of whitespace around the actual graph when one doesn't set a title nor uses their toolbar. 但是,如果没有设置标题或使用工具栏,实际图形周围会有很多空白。 Is there a way to have the graph/chart use more of the canvas? 有没有办法让图表/图表使用更多的画布?

My current solution to add an extra inside the container one and then set it's width and height to be be bigger by the margins I want to remove and the offset it by setting 'top' and 'left' to negative values of the respective margins. 我目前的解决方案是在容器内添加一个额外的,然后将其宽度和高度设置为我要删除的边距更大,并通过将“顶部”和“左”设置为相应边距的负值来抵消它。 Not elegant and more importantly, not robust, but it works for the moment. 不优雅,更重要的是,不健壮,但它暂时起作用。

In ECharts 4.X 在ECharts 4.X中

As mentioned by some other posters, the correct way to get rid of the whitespace is to change options.grid . 正如其他一些海报所提到的,摆脱空白的正确方法是改变options.grid

https://ecomfe.github.io/echarts-doc/public/en/option.html#grid https://ecomfe.github.io/echarts-doc/public/en/option.html#grid

grid: {
  left: 0,
  top: 0,
  right: 0,
  bottom: 0
}

In ECharts 4, the names of the grid properties have been changed to left , right , top , and bottom . 在ECharts 4中,网格属性的名称已更改为leftrighttopbottom

Thanks to the answers above for pointing me in the right direction! 感谢上面的答案,指出我正确的方向!

Further, changing the option.legend , as suggested above, had no effect on my chart. 此外,如上所述,更改option.legend对我的图表没有影响。

You can use the properties defined on the grid (x, y, x2 and y2). 您可以使用网格上定义的属性(x,y,x2和y2)。 These properties are mentioned on the documentation: http://echarts.baidu.com/doc/doc-en.html#Grid 文档中提到了这些属性: http//echarts.baidu.com/doc/doc-en.html#Grid

Adding values to your themes grid object, like so: 向主题网格对象添加值,如下所示:

var theme = {

    grid: {
        x: 40,
        y: 20,
        x2: 40,
        y2: 20
    }

}

In ECharts 3 you can use the options grid.left , grid.top , grid.right and/or grid.bottom . 在ECharts 3中,您可以使用选项grid.leftgrid.topgrid.right和/或grid.bottom According to the documentation, left and right default to 10%, and top and bottom default to 60 (px). 根据文档,左和右默认为10%,顶部和底部默认为60(px)。

Documentation: https://ecomfe.github.io/echarts-doc/public/en/option.html#grid . 文档: https//ecomfe.github.io/echarts-doc/public/en/option.html#grid

const option = {
  // these are the grid default values
  grid: {
    top:    60,
    bottom: 60,
    left:   '10%',
    right:  '10%',
  },
  // your other options...
}

在Echart中,您可以使用图表的组合制作图表/图表,并且每个图表部分的配置太多,如图例等...只需在他们的网站上查看他们的api文档示例页面(组合部分)

legend: {
padding: 0,
itemGap: 0,
data: [' ', ' ']
    },

In here we can just simply remove the padding of the legend. 在这里,我们可以简单地删除图例的填充。 even though you are not specifying one, it is taking the default values. 即使您没有指定一个,它也会采用默认值。 Unfortunately, eCharts doesn't give flexible option of setting chartArea through options. 不幸的是,eCharts没有灵活选择通过选项设置chartArea。 In google Charts you can mention it 100% and it'll cover all the available area. 在Google图表中,您可以100%提及它,它将涵盖所有可用区域。 I tried the above mentioned work around and could cover a bit more space after that. 我尝试了上面提到的工作,之后可以覆盖更多的空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM