javascript - 如何将 HTML 添加到图表元素

标签 javascript angularjs google-visualization

我正在尝试将 Costum HTML 添加到我的 Google 组织结构图中:

$scope.chartElements = [];
$scope.chart = {
    type: "OrgChart",
    data: {
        "cols": [
            {"label": "Name", "pattern": "<div class='text-danger'></div>", "type": "string"},
            {"label": "Manager", "pattern": "", "type": "string"},
        ],
        "rows": $scope.chartElements
    }
};

$http.get(api.getUrl('getMyFamilyTree', null))
    .success(function (response) {
        response.forEach(function (y) {
            $scope.divisionChartElement =
            {
                c: [{v: y.parent_id, f: '<div style="color:red; font-style:italic">President</div>'},
                    {v: y.child_id}
                ]
            };
            $scope.chartElements.push($scope.divisionChartElement);

        });

    });

然而遗憾的是,当它出来时,我得到以下信息:.

enter image description here

谁能帮帮我吗?

fiddle :https://jsfiddle.net/umakk7az/

使用以下 API:https://github.com/bouil/angular-google-chart

最佳答案

我相信您必须将allowHtml 包含到图表对象的选项属性中。

$scope.chartElements = [];
$scope.chart = {
    type: "OrgChart",
    data: {
        "cols": [
        {"label": "Name", "pattern": "<div class='text-danger'></div>", "type": "string"},
        {"label": "Manager", "pattern": "", "type": "string"},
        ],
        "rows": $scope.chartElements
    },
    options:{"allowHtml":true} //Add this attribute
};

$http.get(api.getUrl('getMyFamilyTree', null))
.success(function (response) {
    response.forEach(function (y) {
        $scope.divisionChartElement =
        {
            c: [{v: y.parent_id, f: '<div style="color:red; font-style:italic">President</div>'},
                {v: y.child_id}
            ]
        };
        $scope.chartElements.push($scope.divisionChartElement);

    });

});

关于javascript - 如何将 HTML 添加到图表元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30145417/

相关文章:

charts - 在主测量轴上设置最大值

javascript - 对数据库中的 Google 图表感到困惑

javascript - 如何更改 input.value 返回的内容?

javascript - 我应该担心 HTML5Shiv.min.js 版本 3.7.2 上的这些 JSLint 警告吗?

javascript - 如何在Angularjs中设计下表

javascript - AngularJS 使用 ng-repeat 进行单向数据绑定(bind)和模型编辑

javascript - Angular : scope variables

javascript - 使用javascript获取滚动条的位置

javascript - jquery post 总是返回 false

javascript - 如何根据您传递给它的数据重新绘制 Google 图表?