生成图片

master
夜笙歌 7 months ago
parent 3b56e2f5a7
commit ecb0ddef37

@ -28,12 +28,12 @@
let getColorByTemperature = {}
function getGradientColor(level) {
function getGradientColor(level,sum) {
// 确保级别在1到50之间
level = Math.max(1, Math.min(50, level));
level = Math.max(1, Math.min(sum, level));
// 将级别映射到0到1之间的色相值
const hue = (0.6 - (0.6 / 50) * level) % 1; // 0.6是红色的色相值
const hue = (0.6 - (0.6 / sum) * level) % 1; // 0.6是红色的色相值
const saturation = 1; // 饱和度最大
const value = 1; // 亮度最大
@ -69,15 +69,23 @@
return `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`;
}
for (var i = 0; i <= 10; i++) {
getColorByTemperature[20+i] = getGradientColor(i)
}
const getData = () =>{
$.post(prefix+'/newDataStreak',(e)=>{
console.log(e)
$('#temInfo').html(`<span style="color:#ff0000">最高温度:${e.rows[0].maxTemperature}℃</span> <span style="color:#0b05f7">最低温度:${e.rows[0].minTemperature}℃</span> <span style="color:#0066e4">平均温度:${e.rows[0].avgTemperature}℃</span>`)
$('#timeInfo').html(`<span style="color:#0b05f7">采集时间:${e.rows[0].collectTime}</span> `)
let colors = []
let tems = []
for(i in e.rows[0]){
if(i.includes('site')){
tems.push(e.rows[0][i])
}
}
let sum = Math.max(...tems) - Math.min(...tems)
getColorByTemperature={}
for (var i = 0; i <= sum; i++) {
getColorByTemperature[20+i] = getGradientColor(i,sum)
}
for(i in e.rows[0]){
if(i.includes('site')){
colors.push(getColorByTemperature[e.rows[0][i]])
@ -109,7 +117,7 @@
})
}
getData()
setInterval(getData,1000*60)
setInterval(getData,1000*2)
})
</script>

Loading…
Cancel
Save