如何在Angular nvd3折线图上添加工具提示

时间:2015-11-17 17:51:03

标签: javascript angularjs angularjs-nvd3-directives

我使用以下图表:https://cmaurer.github.io/angularjs-nvd3-directives/line.with.focus.chart.html

我希望能够悬停在图表点上并查看该点的x / y轴值。我注意到我可以在图表中添加tooptip。我试着使用以下内容,但是当我将鼠标悬停在图表上的一个点上时,没有显示任何内容。

$scope.toolTipContentFunction = function(){
      return function(key, x, y, e, graph) {
        return  'Super New Tooltip' +
          '<h1>' + key + '</h1>' +
          '<p>' +  y + ' at ' + x + '</p>'
      }
    };

<div ng-init="dashboardType = 'Bing'">
      <nvd3-line-with-focus-chart
        data="data"
        id="dashboardChart"
        height="400"
        height2="50"
        margin="{left:80,top:50,bottom:30,right:50}"
        yAxisTickFormat="yAxisTickFormatFunction()"
        xAxisTickFormat="xAxisTickFormatFunction()"
        x2AxisTickFormat="xAxisTickFormatFunction()"
        tooltips="true"
        tooltipcontent="toolTipContentFunction()">
        <svg></svg>
      </nvd3-line-with-focus-chart>
    </div>

是否需要使用写入功能来执行我想要的操作?如果是的话 - 我错过了什么吗?我还试图通过将鼠标悬停在图表上来触及toolTipContentFunction功能中的断点,但它并没有停止。不确定这个工具提示应该做什么。

我使用的是Chrome版本46.0.2490.80 m。

1 个答案:

答案 0 :(得分:1)

知道了!我应该将交互模式设置为真。

<nvd3-line-with-focus-chart
        data="data"
        id="dashboardChart"
        height="400"
        height2="50"
        margin="{left:80,top:50,bottom:30,right:50}"
        yAxisTickFormat="yAxisTickFormatFunction()"
        xAxisTickFormat="xAxisTickFormatFunction()"
        x2AxisTickFormat="xAxisTickFormatFunction()"
        tooltips="true"
        interactive="true"
        tooltipcontent="toolTipContentFunction()">
        <svg></svg>
      </nvd3-line-with-focus-chart>