javascript - 在 AngularJS 的数据可视化上下文中调用 D3 工具提示

标签 javascript angularjs d3.js

我正在使用 d3.tip

https://github.com/Caged/d3-tip

当我尝试启动它时它抛出异常(undefined 不是一个函数)

这是我的代码:

define([
'angular',
'app',
'underscore',
'jquery',
'd3',
'require',
],function (angular, app, _, $, d3, localRequire) {
    'use strict';
     var module = angular.module('myModule', []);
     app.useModule(module);
     module.controller('myController', function ($scope, dashboard, querySrv, filterSrv) { ..... }
};


module.directive('myDirective', function () {
        return {
            restrict: 'E',
            link: function (scope, element) {

                scope.$on('render', function () {
                    render_panel();
                });

                angular.element(window).bind('resize', function () {
                    render_panel();
                });

                // Function for rendering panel
                function render_panel() {
                    scope.require(['./d3-tip/d3tip'], function(){
                         var tip = d3.tip().attr('class', 'd3-tip').html(function(d) { return d; });
                         var svg = ......;
                         svg.call(tip);
                    });

这给了我以下异常

TypeError: undefined is not a function
    at Object.<anonymous> (http://localhost:8983/myproject/app/panels/heatmap/module.js:356:42)

对于将 d3.tip 与 AngularJS 和 requireJS 一起使用有什么建议吗?

最佳答案

首先使用以下命令安装 d3-tip。

bower install d3-tip --save

之后你就可以使用 d3.tip 函数了。

d3.tip()

注意:如果使用angular不需要在app.js中注入(inject)

关于javascript - 在 AngularJS 的数据可视化上下文中调用 D3 工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24057073/

相关文章:

javascript - 如何在 Laravel 中使用 ReactJS

javascript - 在es6中导入带有参数的IIFE?

javascript - AngularJS:目录结构(例如模块化编程)会影响加载时间吗?

PHP:如何在不使用 AJAX 调用的情况下更新用户登录计时器

angularjs - 向 logstash 发出发布请求时出现 CORS 错误

javascript - 将 nvd3 linePlusBarChart 改编为具有累积百分比线的直方图?

javascript - 从网页中选择复制将页面超链接添加到剪贴板

javascript - D3.js - JSON 数据数组将相同的数组元素绑定(bind)到所有内容

javascript - 在 d3 中添加图像/图标而不是 svg 形状

javascript - 如何使ticks函数在d3.js中工作?