根据 EasyPieCharts 的动态数据更改 ProgressBar 颜色

Change the ProgressBar color based on dynamic data for EasyPieCharts

我在 angular 中使用 easypiecharts。我正在尝试向标记添加一个属性(data-statusId)并在 js 中使用它来更改进度条的颜色。当 data-opt= 8 时,它应该变成灰色,否则应该是 green.But 我的条件一直失败,因为 greyBar 值一直返回为 "undefined"。

附上截图以供参考。我需要访问 "opt".

数据集下的值

.directive('isLoaded', function () {
    return {
        restrict: 'A', //Attribute type
        link: function (scope, elements, arguments) {
            ProgressMeter($('#inprogress-card').find('.progress-icon'), false);
        }
    }
});
function Meter($ele, isPopUp) {
    setTimeout(function () {
     if (isPopUp && $ele.find('canvas').length > 0) {
       $ele.data('easyPieChart').update(0);
       $ele.data('easyPieChart').update($ele.attr('data-percent'));
     }
     else {         
        $ele.easyPieChart({
            easing: 'easeOutBounce',
            scaleColor: false,
            lineWidth: 4,
            trackColor: '#CCCCCC',
            barColor: function () {
            var greyBar = $ele.data('opt');
                if (typeof(greyBar) != 'undefined')
                    return '#44AD3A'
                else
                    return '#989798'
            },
            lineCap: 'round',
            onStep: function (from, to, percent) {
            }
        });
     }
    }, 100);
}`

HTML:

<div class="progress-icon" data-opt="{{list.Status}}" data-percent=" {{ (20/30)* 100)}} ">

不知为何,我遇到了 data-opt 的问题,.我改用 isolated-scope 。 我将 "opt={{list.Status}}" 添加到 HTML 视图,然后在 js 中,我添加了范围:{opt:'@'}。它奏效了!!

HTML,

<div ng-click="openModal($event,list,id)" opt="{{list.Status}}">
    <div class="progress-icon" data-percent=" {{ (20/30)* 100)}} ">
</div>

js:

.directive('isLoaded', function () {
        return {
            restrict: 'A',
            scope:{
               opt:'@' //*Added this* 
            }
            link: function (scope, elements, arguments) {
               if(scope.opt!=8)
                ProgressMeter($('#inprogress-card').find('.progress-icon'), false,'#44AD3A');
               else
                ProgressMeter($('#inprogress-card').find('.progress-icon'), false,'#989798');
            }
        }
    });
    function Meter($ele, isPopUp) {
        setTimeout(function () {
         if (isPopUp && $ele.find('canvas').length > 0) {
           $ele.data('easyPieChart').update(0);
           $ele.data('easyPieChart').update($ele.attr('data-percent'));
         }
         else {         
            $ele.easyPieChart({
                easing: 'easeOutBounce',
                scaleColor: false,
                lineWidth: 4,
                trackColor: '#CCCCCC',
                barColor: function () {
                var greyBar = $ele.data('opt');
                    if (typeof(greyBar) != 'undefined')
                        return '#44AD3A'
                    else
                        return '#989798'
                },
                lineCap: 'round',
                onStep: function (from, to, percent) {
                }
            });
         }
        }, 100);
    }`