简体   繁体   English

如何减少 eCharts 的填充?

[英]How to reduce the padding from the eCharts?

I am using echarts for visualizing some data in my web-application.我正在使用echarts来可视化我的网络应用程序中的一些数据。 I am using basic gauge chart for the visualization.我正在使用基本仪表图进行可视化。 If you notice the image below, there is too much padding in the chart.如果您注意到下图,则图表中的填充过多。 I would like to remove those padding and ideally have the chart occupy 100% of the space within the container?我想删除那些填充,理想情况下让图表占据容器内 100% 的空间?

Here is the javascript code:这是 javascript 代码:

// Setup chart gauge_basic_options = { // 设置图表 gauge_basic_options = {

            // Add title
            //title: {
            //    text: 'Server resources usage',
            //    subtext: 'Random demo data',
            //    x: 'center'
            //},

            // Add tooltip
            tooltip: {
                formatter: "{a} <br/>{b}: {c}%"
            },

            // Add series
            series: [
                {
                    name: 'Total Invoices',
                    type: 'gauge',
                    center: ['50%', '55%'],
                    detail: {formatter:'{value}%'},
                    data: [
                        {value: 50, name: 'Total Invoices'}
                    ]
                }
            ]
        };

Any idea how to do it?知道怎么做吗?

在此处输入图像描述

In the gauge you also can control the padding with chart radius .在仪表中,您还可以使用图表 半径控制填充。 By default radius is 75% and for fill space completely you need to set new value, example:默认情况下,半径为 75%,对于完全填充空间,您需要设置新值,例如:

 option = { series: [{ name: 'Total Invoices', type: 'gauge', radius: '100%', // this center: ['50%', '50%'], detail: {formatter:'{value}%'}, data: [ {value: 50, name: 'Total Invoices'} ] }] }; var myChart = echarts.init(document.getElementById('main')); myChart.setOption(option);
 <script src="https://cdn.jsdelivr.net/npm/echarts@4.7.0/dist/echarts.min.js"></script> <div id="main" style="width:300px; height:300px;"></div>

The padding is automatically adjusting based on the size of the div.填充会根据 div 的大小自动调整。

Eg: Below div will use the whole page and renders the gauge with plenty of whitespaces例如:下面的 div 将使用整个页面并使用大量空格呈现仪表

<div id="main" style="width: 100vw;height:100vh;"></div>

And below one would be a compact one下面是一个紧凑的

<div id="main" style="width: 100vw;height:100vh;"></div>

Check this fiddle - http://jsfiddle.net/athishayd/x5Lc3mr6/1/检查这个小提琴 - http://jsfiddle.net/athishayd/x5Lc3mr6/1/

I would like to remove those padding and ideally have the chart occupy 100% of the space - This would hamper the gauge's aesthetics.我想删除那些填充,理想情况下让图表占据 100% 的空间——这会妨碍仪表的美观。

I was struggling with the bar chart for the same issue.我正在为同样的问题处理条形图。 Added below in options.在选项下面添加。 This solved it.这解决了它。

grid: {
        x: 0,
        y: 0,
        x2: 0,
        y2: 0
    }

You can specify the spacing of the grid from each edge with a value, in pixels, or percentage:您可以使用值、像素或百分比来指定grid与每个边缘的间距

var option = {
  grid: {
    left: '10%',
    right: '10%',
    top: 0,
    bottom: 0
  }
} 

However, I would warn against using 0 for top or bottom when you have hidden the x-axis.但是,当您隐藏 x 轴时,我会警告不要将0用于topbottom Part of the chart line can get clipped and will look a different thickness if it runs along the base of the axis.图表线的一部分可能会被剪裁,如果它沿着轴的底部延伸,它看起来会有所不同。

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

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