最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I add a custom tooltip to angular-nvd3 multibar chart? - Stack Overflow

programmeradmin3浏览0评论

I cannot get this to work in a multibar chart

$scope.countsChart.options = {
  deepWatchData: false,
  chart: {
    type: 'multiBarChart',
    margin: {
      top: 20,
      right: 20,
      bottom: 45,
      left: 45
    },
    clipEdge: true,
    duration: 500,
    stacked: true,
    showControls: false,
    xAxis: {
      showMaxMin: false,
      tickFormat: d => $scope.countsChart.selectedGranularity().tickFormat(d)
    },
    yAxis: {
      axisLabelDistance: -20,
      tickFormat: d => parseInt(d).toLocaleString()
    },
    useInteractiveGuideline: false,
    interactive: true,
    tooltips: true,
    tooltipContent: (key, x, y, e, graph) => '<h1>Test</h1>'
  }
};

Instead of my custom tooltip, the default tooltip still shows.

Anybody have success making a custom tooltip?

I cannot get this to work in a multibar chart

$scope.countsChart.options = {
  deepWatchData: false,
  chart: {
    type: 'multiBarChart',
    margin: {
      top: 20,
      right: 20,
      bottom: 45,
      left: 45
    },
    clipEdge: true,
    duration: 500,
    stacked: true,
    showControls: false,
    xAxis: {
      showMaxMin: false,
      tickFormat: d => $scope.countsChart.selectedGranularity().tickFormat(d)
    },
    yAxis: {
      axisLabelDistance: -20,
      tickFormat: d => parseInt(d).toLocaleString()
    },
    useInteractiveGuideline: false,
    interactive: true,
    tooltips: true,
    tooltipContent: (key, x, y, e, graph) => '<h1>Test</h1>'
  }
};

Instead of my custom tooltip, the default tooltip still shows.

Anybody have success making a custom tooltip?

Share Improve this question asked Jan 21, 2016 at 23:04 Eric HartfordEric Hartford 18.1k4 gold badges35 silver badges50 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You'll want to use the chart.tooltip.contentGenerator method (ES6 equivalent to what I mocked in this plunker):

$scope.countsChart.options = {
  chart: {
    ...,
    tooltip: {
      contentGenerator: function (key, x, y, e, graph) { 
        return '<h1>Test</h1>';
      }
   // or if you're writing ES6:
   // contentGenerator: (key, x, y, e, graph) => '<h1>Test</h1>'; 
    }
  }
}
发布评论

评论列表(0)

  1. 暂无评论