nvd3:从离散条形图中删除y轴刻度标签

时间:2013-06-21 10:52:13

标签: d3.js nvd3.js

我正在尝试从nvd3中的离散条形图中删除y轴刻度标签。

我已经查看了nvd3源代码,但找不到我可以更改的明显功能。有人能指出我的解决方案吗?

更新:代码

function Transform(value1, value2, chart_name,value3) {
value3 = typeof value3 !== 'undefined' ? value3 : 'no_header';
var chart = nv.models.discreteBarChart()
    .x(function (d) {
    return d.label;
})

    .y(function (d) {
    return d.value;
})

    .staggerLabels(true)
    .tooltips(false)
    .showValues(true);

var a = [];
var f = [{
    values: []
}];
d3.csv("../../csv/master.csv").get(function (error, rows) {

 if (error){
    console.log(error);
    loadError("Uh Oh. This  data set is missing... Try going <a href='/'>back to the start</a>");
    return;
    }

    for (var i = 0; i < rows.length; i++) {
        a.push(rows[i]);
    }
    console.log(a[0].agency);
    for (var key = 0; key < a.length; key++) {
        var b = a[key];
        for (var c in b) {
            if (c != "agency" && c != "division" && c != "pod") {
                var d = b[c];
                a[key][c] = +d;
            }
        }
        console.log(a[0].changes);
        }
  try {
    var e = $.grep(a, function (v) {
      return v.division == {{division|safe}};
        });
    var k = $.grep(e, function(v) {
      return v.agency == {{agency|safe}};
      })[0];
    console.log(k.division);
      }
  catch (TypeError) { loadError("Uh Oh. We could not find this combination\
      of Agency & Division. Try going back to the <a href='/pitchview'>selection menu</a>");
    return;
  }
  if (k.agency){
    for (var g in k) {
        if (g == value1 || g == value2 || g == value3) {
            var h = {
                "label": g,
                    "value": k[g]
            };
            f[0].values.push(h);
        }
    }


    d3.select('#' + chart_name + ' svg')
        .datum(f)
        .transition().duration(500)
        .call(chart)
    nv.utils.windowResize(chart.update);
    return chart;
  } else {
    loadError("Uh Oh. We could not find this combination of Agency &\
        Division. Try going back to the <a href='/pitchview'>selection menu</a>");}});
}

2 个答案:

答案 0 :(得分:20)

nvd3离散条形函数中有一个变量可以删除y轴(包括标签)。在代码中使用它来删除它们:

.showYAxis(false)

x轴存在类似的变量。

答案 1 :(得分:4)

使用chart.yAxis.tickValues(0),它将关闭yticks并保留y Label