首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >angular-nvd3工具提示中的ng-repeat

angular-nvd3工具提示中的ng-repeat
EN

Stack Overflow用户
提问于 2017-02-09 19:05:54
回答 1查看 89关注 0票数 0

我需要在nvd3图的工具提示内容中重复一些值,如何实现它。

我有一个与数据一起发送的JSON,需要在工具提示中重复。我被卡住了,我需要一些帮助来实现这一点。或者有没有其他可以遵循的方法。

代码语言:javascript
复制
 $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,
            },
        };

我需要ng-repeat这个HTML

代码语言:javascript
复制
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
        }
EN

回答 1

Stack Overflow用户

发布于 2017-02-09 19:36:52

您需要在将html传递给graph之前对其进行编译。

代码语言:javascript
复制
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
    }
  }]);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42135009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档