在nvd3中为discreteBarChart指定xDomain会使图表不正确

时间:2017-06-15 16:47:57

标签: d3.js graph nvd3.js

当我尝试在不指定xDomain的情况下绘制discreteBarChart时,以下是输出:Image of the Good graph

当我使用指定xDomain绘制discreteBarChart时,以下是输出:Image of the Bad graph

以下是我用于指定图表选项的代码:

       chart: {
                type: "discreteBarChart",
                height: 350,
                margin : {
                    top: 20,
                    right: 20,
                    bottom: 50,
                    left: 65
                },
                x: function(d){ return d['x']; },
                y: function(d){ return d['y']; },

                xAxis: {
                    axisLabel:  xAxisLabel,                        
                    showMaxMin: false,
                    axisLabelDistance: 2
                },

                yAxis: {
                    axisLabel: yAxisLabel,                        
                    axisLabelDistance: 0,
                },
                legend: {margin: {top: 5}},
                xDomain:[xLowerLimit,xUpperLimit] /* This is where the problem is */
            },
            title: {
                enable :true,
                text: chartTitle
            }

当我指定xDomain时,任何人都可以帮助我理解为什么我会得到如此混乱的discreteBarChart图吗?

我使用的是nvd3 1.8.5。

我发现这个链接(https_://github.com/krispo/angular-nvd3/issues/264)处理了linePlusBarChart的类似问题。该链接中提到的解决方案是使用' xDomain'来编辑nvd3源文件。相关代码。为了尝试相同的方法,我查看了源代码,但发现离散的BARChart的xDomain部分对我的眼睛有好处。

1 个答案:

答案 0 :(得分:0)

  chart: {
            type: "discreteBarChart",
            height: 350,
            margin : {
                top: 20,
                right: 20,
                bottom: 50,
                left: 65
            },
            x: function(d){ return d['x']; },
            y: function(d){ return d['y']; },

            xAxis: {
                axisLabel:  xAxisLabel,                        
                showMaxMin: false,
                axisLabelDistance: 2
            },

            yAxis: {
                axisLabel: yAxisLabel,                        
                axisLabelDistance: 0,
            },
            legend: {margin: {top: 5}},
            forceX: [xLowerLimit,xUpperLimit]
        },
        title: {
            enable :true,
            text: chartTitle
        }
相关问题