如何使用jquery显示旋钮图表上的值? 如何在Bootstrap4中使用jQuery旋钮图表显示从某个URL获取的值。我得到了“NaN”值。(请参阅下面的代码) 如果数据为空,如何显示“-”破折号。(请参阅下面的代码)
HTML如何使用jquery显示旋钮图表上的值? 如何在Bootstrap4中使用jQuery旋钮图表显示从某个URL获取的值。我得到了“NaN”值。(请参阅下面的代码) 如果数据为空,如何显示“-”破折号。(请参阅下面的代码),jquery,html,ajax,bootstrap-4,jquery-knob,Jquery,Html,Ajax,Bootstrap 4,Jquery Knob,HTML <input type="text" class="knob" id="avg_temperature" data-width="120" data-height="120" data-thickness="0.40" data-fgColor="#000000" readonly> JS $.ajax({ url : XXX, type : 'POST', dataType : 'json', cache: false, as
<input type="text" class="knob" id="avg_temperature" data-width="120" data-height="120" data-thickness="0.40" data-fgColor="#000000" readonly>
JS
$.ajax({
url : XXX,
type : 'POST',
dataType : 'json',
cache: false,
async: false,
dataSrc : 'data',
contentType: false,
processData: true,
success: function(response){
if (response.status == "Success"){
if (response.data[0]["avg_temperature"] == null){
response.data[0]["avg_temperature"] = "-";
$("#avg_temperature").text("-");
}
$("#avg_temperature").text(response.data[0]["avg_temperature"]);
var colors = ['#11E117', '#FFC300', '#C00']
//knob chart for temperature
$('#avg_temperature').knob();
$('#avg_temperature').attr('data-fgColor', '#11E117');
$({animatedVal: 0}).animate({animatedVal: response},{
duration: 3000,
easing: "swing",
async: false,
step: function() {
var val = Math.ceil(this.animatedVal);
$("#avg_temperature").trigger('configure', {
'fgColor': colors[(val < 40) ? 0 : (val < 70) ? 1 : 2]
}).val(val).trigger("change");
var newVal = val + String.fromCharCode(176) + 'C'; $('#avg_temperature').val(newVal);
}
});
}
},
});
$.ajax({
网址:XXX,
键入:“POST”,
数据类型:“json”,
cache:false,
async:false,
dataSrc:'数据',
contentType:false,
processData:对,
成功:功能(响应){
如果(response.status==“Success”){
如果(响应数据[0][“平均温度”]==null){
响应。数据[0][“平均温度”]=“-”;
$(“#平均温度”)。文本(“-”;
}
$(“平均温度”).text(response.data[0][“平均温度”);
变量颜色=['#11E117'、'#FFC300'、'#C00']
//温度旋钮图
$('平均温度').旋钮();
$('avg#u temperature').attr('data-fgColor','11E117');
$({animatedVal:0}).animate({animatedVal:response}{
时长:3000,
放松:“挥杆”,
async:false,
步骤:函数(){
var val=Math.ceil(this.animatedVal);
$(“#平均温度”).trigger('configure'{
“fgColor”:颜色[(val<40)?0:(val<70)?1:2]
}).val(val).触发(“变更”);
var newVal=val+String.fromCharCode(176)+“C”;$(“#平均温度”).val(newVal);
}
});
}
},
});
从代码的上下文来看,响应
似乎是一个对象,这就是问题的原因,因为animate()
希望您提供的值是一个整数
从代码中其他地方使用response
的上下文来看,您似乎需要从中访问特定的temperature
属性,如下所示:
if(响应数据[0][“平均温度”]==null)
响应。数据[0][“平均温度”]=“-”;
变量颜色=['#11E117'、'#FFC300'、'#C00']
让$avgTemp=$(“#avg_温度”).text(response.data[0][“avg_温度”);
$avgTemp.data('fgColor','#11E117')。旋钮();
$({
动画值:0
}).制作动画({
animatedVal:parseInt(response.data[0][“avg_temperature”],10)//在此处更新
}, {
时长:3000,
放松:“挥杆”,
步骤:函数(){
var val=Math.ceil(this.animatedVal);
$avgTemp.trigger('configure'{
“fgColor”:颜色[(val<40)?0:(val<70)?1:2]
}).val(val).触发(“变更”);
var newVal=val+String.fromCharCode(176)+'C';
$avgTemp.val(新val);
}
});
还要注意删除了
async:false
。这是一种不好的做法,在这里你无论如何也不需要它这似乎是孤立的。请在问题中添加问题的工作示例,以便我们创建MCVE。注意,AJAX部分可以删除,因为它与问题无关。我已经在该链接中提供了代码。用于HTML和JS。如果这还不够,请告诉我。响应的值是多少?我创建了一个变量$(“#平均温度”)。val=“90”
作为值。不,我问了响应
参数在$.ajax
调用中的值是多少。您正在animate()
方法中使用此选项。我假设它是一个对象,不是一个整数,所以你错了。从上下文来看,您应该使用…animate({animatedVal:parseInt(response.data[0][“avg_temperature”]”,10)})
Hi,只是想知道整数“10”的函数在答案行中的作用是什么?它是基数:Hi,你能帮我解决这个问题吗?