如何隐藏nvd3图表上的第一个Y轴线?

时间:2015-09-29 19:14:26

标签: javascript angularjs d3.js charts nvd3.js

Plnkr示例: http://plnkr.co/edit/19D5cnrVYdUrMlblQARy?p=preview

我的应用截图: enter image description here

我尝试修改CSS,但是我只能删除第二条(右Y轴线),而不是第一条左Y轴线。

我尝试了什么:

.nv-y { 
    display: none;
}

以及此答案的所有内容:Alter first vertical grid line in nvd3

d3.selectAll('.nv-y').attr('display','none')

d3.selectAll('.nv-y path').attr('opacity','0.1')

d3.selectAll('.nv-y path').attr('display','none')

我当前的drawChart功能:

function drawChart(res) {
    console.log(' ');
    console.log('drawChart res = ',res);
    nv.addGraph(function() {
        var chart = nv.models.linePlusBarChart()
            .margin({top: 30, right: 40, bottom: 50, left: 40})
            .x(function(d,i) { return i })
            .y(function(d) { return d[1] })
            .color(d3.scale.category10().range());

        chart.xAxis.tickFormat(function(d) {
            var dx = res[0].values[d] && res[0].values[d][0] || 0;
            return d3.time.format('%x')(new Date(dx))
        });

        chart.y1Axis
            .tickFormat(d3.format(',f'));

        chart.y2Axis
            .tickFormat(function(d) { return '$' + d3.format(',f')(d) });

        chart.bars.forceY([0]);
        // https://stackoverflow.com/questions/23754188/nvd3-js-how-to-disable-tooltips-for-one-serie-only
        chart.lines.interactive(false);
        // http://nvd3-community.github.io/nvd3/examples/documentation.html#line
        chart.height(280);
        // If not chart data is avaliable to display:
        chart.noData("There is no Data to display at the moment.");

        // Remove legend:
        chart.showLegend(false);

        d3.select('#chart svg')
            .datum(res)
            .transition().duration(500)
            .call(chart);

        d3.selectAll('.nv-y path').attr('display','none');

        nv.utils.windowResize(chart.update);

        return chart;
    });
}

2 个答案:

答案 0 :(得分:2)

如果你想隐藏第一个y轴,请执行:

.nv-y1{
  display:none;
}

如果要隐藏第二个y轴,请执行以下操作:

.nv-y2{
  display:none;
}

http://plnkr.co/edit/IgFh1rV4a6ubAMe0VqT2?p=preview

答案 1 :(得分:1)

使用此:

.domain {
  display: none;
}