【问题标题】:Howto set custom ticks and labels on Y axis in nvd3如何在 nvd3 的 Y 轴上设置自定义 xticks 和标签
【发布时间】:2015-06-24 00:31:18
【问题描述】:

我想为我在 nvd3 中完成的离散图表设置自定义刻度数和标签。问题是标签和值需要以 10:1、8:1 等比例显示,但实际条形高度显示为数字 10、8 等。有没有办法在 y 轴和鼠标悬停时创建自定义标签nvd3 中的工具提示?

【问题讨论】:

    标签: d3.js nvd3.js


    【解决方案1】:

    您可以使用tickFormat(实际上是原始 D3 方法)来做到这一点:

    chart.yAxis
        .tickFormat(function (d) {
            return  d + ':' + 1;
        });
    

    NVD3 将自动在工具提示中使用该格式。

    如果您想单独编辑工具提示内容,您可以使用 tooltipContent 方法(可能会添加其他方法in the next release of NVD3)。

    chart.tooltipContent(function (key, x, y, e, graph) {
        return '<h3>' + key + '</h3>' +
            '<p>' +  y + ' on ' + x + '</p>';
    });
    

    this Plunker

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多