javascript - 如何在c3.js中调整条形图的大小

标签 javascript bar-chart c3.js

我想让 c3.js 图表比现在的实际尺寸小。我调整了宽度,但如果不是 620,它会 chop 较大的值。

红色图表为 620 像素。我希望它是第一个图表的大小,所有值都显示,没有任何淡出/截止。

enter image description here

var chart = c3
            .generate({
                bindto : "#topSources",
                size : {
                    height : 180,
                    width : 620
                },
                bar : {
                    width : 16
                },
                padding : {
                    right : 230,
                    top : 50
                },
                color : {
                    pattern : [ '#008000', '#008000', '#008000', '#008000',
                            '#008000' ]
                },
                data : {
                    columns : [ [ 'Throughput', data.columns[0][1],
                            data.columns[0][2], data.columns[0][3],
                            data.columns[0][4], data.columns[0][5] ] ],
                    type : 'bar',
                    labels : {
                        format : {
                            Throughput : d3.format('$'),

                        }
                    },

                    color : function(inColor, data) {
                        var colors = [ '#008000', '#008000', '#008000',
                                '#008000', '#008000' ];
                        if (data.index !== undefined) {
                            return colors[data.index];
                        }

                        return inColor;
                    }
                },
                axis : {
                    rotated : true,
                    x : {
                        type : 'category',
                        show : false,
                    },
                    y : {
                        show : false
                    }
                },
                tooltip : {
                    grouped : false
                },
                legend : {
                    show : false
                }
            });

最佳答案

设置轴填充值(在本例中为 y 轴底部,因为它是旋转条形图)。 80px 将覆盖标签的大部分长度 - 如果您更改字体大小等,则需要有所不同

axis : {
      ...
      y : {
         show : false,
         padding: {  // use these 3 lines
            bottom: 80,
         },
      }
},

关于javascript - 如何在c3.js中调整条形图的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42557101/

相关文章:

javascript - 取消后提交仍在继续Confirm()

javascript - 使用 PHP 或 JS 对 @media 查询中的 html 元素进行优先级排序

javascript - Google Charts,设置条形图的网格线数

javascript - 为 C3JS 定制的工具提示

javascript - 参数左侧无效 - 引用错误

javascript - 如何替换捕获组而不是 RegEx 中的完整匹配项?

javascript - 自动滚动到焦点输入 View

python - 如何在 python 中使用 Plotly 离线模式绘制条形图?

android - 具有各种条宽的 MPAndroidChart 条形图

javascript - C3js : How to hide ticks on y-axis? Y轴标签被 chop