简体   繁体   English

摆脱C3图表上的顶部/底部边距/填充

[英]Get rid of top/bottom margin/padding on C3 Chart

I have a few charts which I'm trying to fit snuggly into a div. 我有一些图表要与div紧密配合。 I can't seem to make the top/bottom white space go away. 我似乎无法消除顶部/底部的空白。 Ideally the top of the graph and the bottom legend would fit snuggly against the div. 理想情况下,图表的顶部和底部的图例将紧贴div。 Any ideas? 有任何想法吗? I've tried the padding options, but they don't seem to affect that specific white space. 我已经尝试过填充选项,但是它们似乎并不影响特定的空白。

http://jsfiddle.net/264v700x/5/ http://jsfiddle.net/264v700x/5/

var chart = c3.generate({
        padding: {
          top: 0,
          bottom: 0
        },
        data: {
          json: [{
            date: '2014-02-02',
            download: 100,
            total: 500
          }],
        keys: {
          x: 'date',
          value: ['why']
        }
    },
    axis: {
        x: {
          type: 'timeseries',
            tick: {
              format: function (x) {
                if (x.getDate() === 1) {
                        return x.toLocaleDateString();
                }
              }
            }
        }
    }
});

CSS/JS hacks welcome! 欢迎CSS / JS骇客! I'd like it to fit the div and not have to specify a height, but if specifying a height is the only way, I can work around it. 我希望它适合div,而不必指定高度,但是如果指定高度是唯一的方法,我可以解决这个问题。

Any help is appreciated. 任何帮助表示赞赏。

Update: I went through c3.js and it looks like this is being added in the javascript somewhat statically. 更新:我经历了c3.js,它看起来像是被静态地添加到了javascript中。 I'll have to refactor the code to work around this. 我将不得不重构代码来解决此问题。

For anyone else wondering - this space comes from these lines of code in c3's code: 对于任何其他想知道的人-这个空间来自c3代码中的以下代码行:

$$.margin = config.axis_rotated ? {
    top: $$.getHorizontalAxisHeight('y2') + $$.getCurrentPaddingTop(),
    right: hasArc ? 0 : $$.getCurrentPaddingRight(),
    bottom: $$.getHorizontalAxisHeight('y') + legendHeightForBottom + $$.getCurrentPaddingBottom(),
    left: subchartHeight + (hasArc ? 0 : $$.getCurrentPaddingLeft())
} : {
    top: 0+ $$.getCurrentPaddingTop(), // for top tick text
    right: hasArc ? 0 : $$.getCurrentPaddingRight(),
    bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$.getCurrentPaddingBottom(),
    left: hasArc ? 0 : $$.getCurrentPaddingLeft()
};

You can either manually adjust it, or add code to allow for zero margin situations. 您可以手动调整它,也可以添加代码以允许出现零边距的情况。

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

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