javascript - dc.js 月图表条间距不均匀

标签 javascript d3.js dc.js

我正在使用 dc.js 创建图表,您可以看到月份之间的间隔不同。最值得注意的是二月和三月之间,因为二月只有 28 天。我如何在月份之间保持均匀的间隔?

           chart
                //dimensions
                .height(250)
                .margins({top: 10, right: 50, bottom: 25, left: 50})
                //x-axis
                .x(d3.time.scale().domain(domain))
                .round(d3.time.month.round)
                .xUnits(d3.time.months)
                .elasticX(true)
                .xAxisPadding(20)
                //left y-axis
                .yAxisLabel('Dollars')
                .elasticY(true)
                .renderHorizontalGridLines(true)
                // right y-axis
                .rightYAxisLabel('Quantity')
                //composition
                .compose(composition)

                .brushOn(false)
                .xAxis().tickFormat(d3.time.format('%b %y'));

Chart

最佳答案

我想你忘了设置gap

  magnitudeChart.width(480) //you should also set the chart width too
    .height(150)
    .margins({top: 10, right: 10, bottom: 20, left: 40})
    .dimension(magValue)
    .group(magValueGroupCount)
    .transitionDuration(500)
    .centerBar(true)    
    .gap(65) //set the gap
    .filter([3, 5])
    .x(d3.scale.linear().domain([0.5, 7.5]))
    .elasticY(true)
    .xAxis().tickFormat(); 

dc bar reference

关于javascript - dc.js 月图表条间距不均匀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23944014/

相关文章:

grails - DC Crossfilter隐藏特定选择

javascript - 设置 dc.js/d3 图表中 y 轴值的格式

javascript - CSS3 过渡卡住

javascript - 试图利用分享社交按钮的值(value)来进行操纵

javascript - 数据表按钮破坏了搜索功能

javascript - 函数返回数字,但对象被存储

javascript - 如何在 d3 树布局中仅显示特定节点级别

javascript - d3.js - 通过 csv 在饼图中显示层次结构

javascript - 在 dc js 中创建堆叠条形图

javascript - 隐藏 TinyNav 子菜单