Javascript 在angular-nvd3工具提示中重复ng
我需要重复nvd3图形中工具提示内容中的一些值,如何实现它 我有一个JSON随数据一起发送,需要在工具提示中重复。我陷入困境,我需要一些帮助来实现这一点。或者有没有其他可以遵循的方法Javascript 在angular-nvd3工具提示中重复ng,javascript,angularjs,nvd3.js,angular-nvd3,Javascript,Angularjs,Nvd3.js,Angular Nvd3,我需要重复nvd3图形中工具提示内容中的一些值,如何实现它 我有一个JSON随数据一起发送,需要在工具提示中重复。我陷入困境,我需要一些帮助来实现这一点。或者有没有其他可以遵循的方法 $scope.options = { chart: { type: 'multiBarHorizontalChart', height: 380, width: 350,
$scope.options = {
chart: {
type: 'multiBarHorizontalChart',
height: 380,
width: 350,
x: function(d) {
return d.label;
},
y: function(d) {
return d.value;
},
showControls: false,
showValues: true,
showLegend: false,
duration: 1000,
xAxis: {
showMaxMin: false
},
yAxis: {
axisLabel: 'Values',
axisLabelDistance: 100,
tickFormat: function(d) {
return d3.format('.0f')(d);
}
},
"tooltip": {
"enabled": true,
"headerEnabled": true,
"valueFormatter": function(d, i) {
"use strict"
return;
},
"keyFormatter": function(d, i) {
var i = curr.split('$')
return i[1];
},
contentGenerator: function(key, x, y, e, graph) {
if (key.data.tooltip.length != 0) {
return html(key)
} else
return "No Data to Show";
}
}
},
title: {
enable: false,
},
};
我需要重复这个HTML
function IpHtml(key) {
var head = $scope.iptraffic.category;
var html = '<div class="toolTipTraffic">' +
'<div class="head">' +
' <b>' + head + '</b>' +
'</div>' +
' <hr>' +
' <table class="table toottipTableTraffic">' +
' <tr ng-repeat=vals in key>' + // ng-repeat here
' <td>IP</td>' +
' <td>' + ': {{vals}}' + '</td>' +
' </tr>' +
' </table>' +
'</div>';
return html
}
功能IpHtml(按键){
var head=$scope.iptraffic.category;
var html=''+
'' +
''头+''号+
'' +
“
”+
' ' +
''+//ng重复这里
“知识产权”+
''+':{{vals}}'+''+
' ' +
' ' +
'';
返回html
}
在将html传递给graph之前,您需要编译html
angular.module('exampleApp', [])
.controller('exampleController', ['$scope', '$compile', function ($scope, $compile) {
function IpHtml(key) {
var tooltipScope = $scope.$new(false); // inherit from parent, so we can use 'iptraffic.category' for header
tooltipScope.key = key;
var html = '<div class="toolTipTraffic">' +
'<div class="head">' +
' <b ng-bind="iptraffic.category"></b>' +
'</div>' +
' <hr>' +
' <table class="table toottipTableTraffic">' +
' <tr ng-repeat=vals in key>' + // ng-repeat here
' <td>IP</td>' +
' <td>' + ': {{vals}}' + '</td>' +
' </tr>' +
' </table>' +
'</div>';
var element = $compile(html)(tooltipScope);
return element[0].outerHTML
}
}]);
角度模块('exampleApp',[])
.controller('exampleController',['$scope','$compile',函数($scope,$compile){
功能IpHtml(键){
var tooltipScope=$scope.$new(false);//从父级继承,因此我们可以使用“iptraffic.category”作为标题
tooltipScope.key=键;
var html=''+
'' +
' ' +
'' +
“”+ ' ' + ''+//ng重复这里 “知识产权”+ ''+':{{vals}}'+''+ ' ' + ' ' + ''; var元素=$compile(html)(工具提示); 返回元素[0]。outerHTML } }]);
我将尝试@TheSameson我尝试过,它工作正常,但我无法返回带值的HTML,它只返回HTML结构,其中没有数据,但当我控制台记录“元素[0]”时。我可以看到预期的HTML结构和数据