Javascript 查询';数据值';填充条件If语句的步骤

Javascript 查询';数据值';填充条件If语句的步骤,javascript,html,jquery,css,Javascript,Html,Jquery,Css,对于每个.round div,都有一个数据值(%),该值目前是静态的,但最终将是动态的。尝试在my JS中调用它,如果数据值0.50&&data值0.75显示为绿色 要调用该值并将圆函数包装在条件中,我将如何进行 我尝试了以下操作,它告诉无法读取null的属性“getAttribute”: 我尝试了this.getAttribute('data-value') 这是具有上述“解决方案”的JS,但不填充任何内容: function Circle(el){ var a = document.que

对于每个.round div,都有一个数据值(%),该值目前是静态的,但最终将是动态的。尝试在my JS中调用它,如果数据值0.50&&data值0.75显示为绿色 要调用该值并将圆函数包装在条件中,我将如何进行

我尝试了以下操作,它告诉
无法读取null的属性“getAttribute”:
我尝试了
this.getAttribute('data-value')

这是具有上述“解决方案”的JS,但不填充任何内容:

function Circle(el){

var a = document.querySelector("a");
console.log(a.getAttribute('data-value'));

if(a.getAttribute('data-value') <= 0.50){
    $(el).circleProgress({fill: {color: 'red'}})
    .on('circle-animation-progress', function(event,
    progress, stepValue){

        $(this).find('strong').text(String(stepValue.toFixed(2)).substr(2) + '%');
    });
    }
if(a.getAttribute('data-value') > 0.50 && a.getAttribute('data-value') <= 0.75){
    $(el).circleProgress({fill: {color: 'yellow'}})
    .on('circle-animation-progress', function(event,
    progress, stepValue){

        $(this).find('strong').text(String(stepValue.toFixed(2)).substr(2) + '%');
    });
    }
if(a.getAttribute('data-value') > 0.75){
    $(el).circleProgress({fill: {color: 'green'}})
    .on('circle-animation-progress', function(event,
    progress, stepValue){

        $(this).find('strong').text(String(stepValue.toFixed(2)).substr(2) + '%');
    });
    }

 };

Circle('.round');

晨报跟踪器
晨报跟踪器
按地点

科威特 阿尔巴尼亚 澳大利亚 关岛 泰国 叙利亚 日本 出勤率
要读取集合中每个元素的
数据
属性,您需要获取对它的引用。由于的
fill.color
属性只接受字符串,而不接受函数,因此需要使用
each()
循环来完成此操作

从这里可以直接确定值并返回相关颜色。试试这个:

功能圈(选择器){
$(选择器)。每个((i,el)=>{
设$el=$(el);
让value=$el.data('value');
$el.circleProgress({
填充:{color:value<0.5?'red':value<0.75?'yellow':'green'}
}).on('circle-animation-progress',函数(事件、进度、步长值){
$(this).find('strong').text((stepValue*100).toFixed(0)+'%');
});
});
};
圆('.round');
$('.btn')。在('click',()=>Circle('.round'))上
#圆圈栏{
边缘顶部:50px;
文本对齐:居中;
字体系列:tahoma;
}
#圆形,圆形{
最小高度:255px;
边缘顶部:30px;
位置:相对位置;
边缘底部:20px;
}
#圆棒,圆棒{
位置:绝对位置;
最高:50%;
左:50%;
利润上限:-50px;
转换:翻译(-50%);
字体大小:40px;
颜色:#212121;
字号:100;
}
#圆跨距{
显示:块;
颜色:#999;
字号:17px;
边缘顶部:10px;
}
#圆杆跨度i{
颜色:#104723;
字体大小:22px;
右边距:7px;
}
区段按钮:活动{
背景色:#104723;
边框颜色:#b3ab7d;
}
区段按钮:悬停{
背景色:#104723;
边框颜色:#b3ab7d;
}

晨报跟踪器
按地点

科威特 阿尔巴尼亚 澳大利亚 关岛 泰国 叙利亚 日本 出勤率
非常感谢Rory!没问题,很高兴为您提供帮助如何使数据可视性更小?当我从200->100更改数据大小属性时,数据大小属性会缩小,但数据值无法更改大小以插入回数据可视化中