简体   繁体   English

多余的空格从哪里来?

[英]Where is this extra whitespace coming from?

I'm creating gauge charts using c3.js . 我正在使用c3.js创建量表。 I'm setting the height and width both to 75 because that's the right size of the gauge that I'm wanting, however when they get generated, there's always extra whitespace in the container that's messing me up. 我将高度和宽度都设置为75因为这是我想要的量规的正确尺寸,但是,当它们生成时,容器中总是存在多余的空格,这使我感到困惑。

在此处输入图片说明

I really want the svg that gets created to have a height of 60 in order to move the label up properly. 我真的希望创建的svg具有60的高度,以便正确地向上移动标签。 The problem, is that when I set the height/width of the chart to 60, the size of the gauge itself gets way too small because of this extra whitespace. 问题是,当我将图表的高度/宽度设置为60时,由于存在额外的空白,仪表本身的尺寸变得太小了。

I've tried setting the padding of everything that I know of to 0. I've searched through the documentation, there's always a chance that I've overlooked something. 我尝试将我所知道的所有内容的填充都设置为0。我在文档中进行了搜索,总是有可能忽略了某些内容。 I can always try to do some hacky css to get around it, but before I do that, I'd like to change something in the configuration if I can. 我总是可以尝试做一些棘手的CSS来解决它,但是在我这样做之前,如果可以的话,我想更改配置。

Essentially, I want the chart to take up the full size that I specify. 本质上,我希望图表占据我指定的完整大小。 It seems that the legend, that I've specified to not show, is still taking up space that the chart should use. 我指定不显示的图例似乎仍在占用图表应使用的空间。

http://jsfiddle.net/kLsox4ya/1/ http://jsfiddle.net/kLsox4ya/1/

<div class='row'>
  <div class="col-12" id="chart"></div>
  <p class="col-12 f-small">PERFECT</p>
</div>

var chart = c3.generate({
   bindto: '#chart',
   data: {
       columns: [['data', 0]],
       type: 'gauge'
   },
   gauge: {
       fullCircle: true,
       startingAngle: 2 * Math.PI,
       width: 3,
       expand: false,
       label: {
          show: false
        }
   },
   size: {
       height: 75,
       width: 75
   },
   legend: {
       show: false
   },
   interaction: {
       enabled: false
   }

});

You are going to have a hard time getting that much control over c3 . 您将很难控制c3 It's doing a lot under the hood to calculate positions for axis, legends, etc... that you aren't even using. 要计算甚至不使用的轴,图例等位置,要花很多时间。

I think you have two options: 我认为您有两种选择:

  1. Code it yourself using straight d3 使用直d3自己编码
  2. Resort to a little hackery. 求助于一点黑客。 For instance here , I've manually adjust the height after it renders. 例如在这里 ,我在渲染后手动调整了高度。

 var chart = c3.generate({ bindto: '#chart', data: { columns: [['data', 90]], type: 'gauge' }, tooltip: { show: false }, color: { pattern: ['#565656', '#cfd628', '#e8b532', '#28d632'], threshold: { values: [40, 80, 90, 100] } }, gauge: { fullCircle: true, startingAngle: 2 * Math.PI, width: 3, label: { format: function (value, ratio) { return ''; }, extents: function (value) { return ''; } } }, size: { height: 75, width: 75 }, legend: { show: false }, interaction: { enabled: false }, axis: { x: { show: false }, y: { show: false } }, padding: { top: 0, right: 0, bottom: 0, left: 0 }, onrendered: function(){ this.svg.attr('height', 55); } }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.12/c3.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.12/c3.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script> <div class='row'> <div class="col-12" id="chart"></div> <p class="col-12 f-small">PERFECT</p> </div> 

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

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