angular.js - angularjs directive + D3, scope数据更新后,重新生成可视化图后新图直接覆盖在老图之上
淡淡烟草味
淡淡烟草味 2017-05-15 16:50:46
0
1
604

加了transclude,应该把template里的内容清空的,但是每次update数据后原来的图都在,哪里写错了吗,跟有关吗?

directive

myApp.directive('sankeyChart', function($window){
    return{
        restrict:'EA',
        transclude: true, //加了transclue
        template:"<svg width='1200' height='600'></svg>",
        scope:{chartData:'=chartData'},
        link: function(scope, elem, attrs){
            scope.$watch('chartData', function(nv){
                var dataToPlot=nv;
                var d3 = $window.d3;
                、、、、下面都是d3的代码、、、、、、、

调用directive

<p sankey-chart chart-data="sankeyData" ng-if="sankeyData" class="myCharts"></p>

如下图:

淡淡烟草味
淡淡烟草味

reply all(1)
小葫芦

Erase, I found the problem. Transclude cannot erase the contents of the svg generated by d3. I manually add a code to clear the contents of the svg before writing the d3 code - it's done.

svg.selectAll('*').remove();
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template