javascript - 顶线填充 Nvd3 图表

标签 javascript angularjs d3.js

我的 Angular-nvd3 图表遇到这个问题,它们是 linePlusBarChart 并且工作正常,但如果我将插值更改为 cardinal 我会得到一条类似的线屏幕截图中显示了一个。

我该如何解决这个问题?

我的图表选项:

vm.chartOptions = {
    chart: {
        type: 'linePlusBarChart',
        height: 450,
        margin: {
            top: 0,
            right: 50,
            bottom: 50,
            left: 50
        },
        focusEnable: false,
        duration: 250,
        forceY: [0],
        groupSpacing: 0.5,
        interpolate: 'cardinal',
        xAxis: {
            axisLabel: false,
            showMaxMin: false,
            tickFormat: function(d) {
                return d3.time.format('%b %y')(new Date(d));
            }
        },
        y1Axis: {
            showMaxMin: false,
            tickFormat: function(d) {
                if (d > 0) return '$' + d3.format(',f')(d);
            }
        },
        y2Axis: {
            showMaxMin: false,
            tickFormat: function(d) {
                if (d > 0) return d3.format(',f')(d);
            }
        }
    }
};

The chart

最佳答案

我通过使用 forceY 参数操纵 Y 轴解决了这个问题:

var values = [1, 2, 3, 4], // the chart values this is only for example
    maxY = 0,
    forceY = [0];

if (values && values.length) {
    maxY = _.max(values, function(o) {
        return o.y;
    });
}
if (maxY && maxY.y) {
    forceY = [0, (maxY.y * 15 / 100) + maxY.y];
}

然后只需将参数forceY:forceY添加到图表

关于javascript - 顶线填充 Nvd3 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40241684/

相关文章:

javascript - 参数解构(相当于python的double-splat)

angularjs - Mongodb 节省了一天的时间 - 时区问题

javascript - 如果手动关闭,UI Bootstrap 下拉开关需要单击两次

javascript - 错误: Invalid value for <circle> attribute cx ="NaN" in dimple.js

javascript - 在 d3 中单击按钮执行 Javascript 文件

javascript - "Client-Side JavaScript"、 "Server-side JavaScript"和 "CoreJavaScript"之间的区别

javascript - 在没有 jQuery AJAX 的情况下在 React 中提交表单

angularjs - http请求多浏览器的烦恼

javascript - D3 - 刷图表时重置缩放?

javascript - 如果封闭的 DIV 属性发生变化,Firefox 将重新启动 Flash 电影