随着科技的发展,数据可视化在各个领域中的应用越来越广泛。在温度监控和展示方面,传统的温度计已逐渐被数字化温度计所取代。本文将介绍一个使用Echarts库创建的温度计Web图表,该图表通过动态数据可视化展示了温度值,并通过渐变色和刻度设计增加了温度计的真实感。
项目需求
在我们的项目中,我们需要创建一个温度计图表,它可以实时展示温度值,并具有渐变色的温度刻度。此外,我们还希望温度计的显示内容能够根据温度值的变化而变化,例如当温度偏高时显示特定的文本。
技术选型
为了实现这个项目,我们选择了 ECharts 作为我们的图表库。ECharts 提供了多种图表类型,包括条形图、折线图、饼图等,并且可以轻松地自定义图表样式和交互功能。此外,ECharts 支持响应式设计,能够适应不同大小的屏幕。
实现过程
-
初始化 ECharts 实例:我们首先需要在 HTML 页面中引入 ECharts 库,并创建一个图表容器。然后,我们可以通过 JavaScript 初始化 ECharts 实例,并设置图表的基本配置。
-
配置图表系列:我们创建了多个系列,包括温度计的显示内容、温度刻度、温度计柱等。每个系列都有其独特的配置,如类型、数据、样式等。
-
温度值和显示内容的处理:我们定义了温度值 TP_value 和显示内容 TP_txt,并根据温度值的不同范围,设置了不同的显示内容和渐变色。
-
温度刻度的处理:我们使用了一个循环来构造温度刻度,并根据温度值的不同范围,设置了不同的刻度值。
-
温度计柱的处理:我们设置了温度计柱的渐变色和样式,并根据温度值的不同范围,设置了不同的显示内容和样式。
-
显示内容和定位的处理:我们设置了显示内容和定位,并根据温度值的不同范围,设置了不同的显示内容和定位。
-
避免温度过低 右侧指示内容出界:我们设置了温度计柱的宽度,并根据温度值的不同范围,设置了不同的宽度。
实现代码
通过以上步骤,我们成功地创建了一个温度计的数字化呈现。该图表可以实时展示温度值,并具有渐变色的温度刻度。代码如下:
var TP_value = 10; // 温度
var kd = []; // 刻度
var Gradient = []; // 存放颜色的数组
var leftColor = ''; // 显示文本的颜色
var showValue = ''; // 显示内容 温度数字
var boxPosition = [65, 0]; // 显示内容的定位
var TP_txt = ''; // 显示内容 文本// 刻度使用柱状图模拟,短设置1,长的设置3;构造一个数据
for (var i = 0, len = 135; i <= len; i++) {if (i < 10 || i > 130) {kd.push('')} else {if ((i - 10) % 20 === 0) {kd.push('-3');} else if ((i - 10) % 4 === 0) {kd.push('-1');} else {kd.push('');}}
}//中间线的渐变色和文本内容
if (TP_value > 20) {TP_txt = '温度偏高';Gradient.push({offset: 0,color: '#93FE94'}, {offset: 0.5,color: '#E4D225'}, {offset: 1,color: '#E01F28'})
}
else if (TP_value > -20) {TP_txt = '温度正常';Gradient.push({offset: 0,color: '#93FE94'}, {offset: 1,color: '#E4D225'})
}
else {TP_txt = '温度偏低';Gradient.push({offset: 1,color: '#93FE94'})
}
if (TP_value > 62) {showValue = 62
}
else {if (TP_value < -60) {showValue = -60} else {showValue = TP_value}
}
// 避免温度过低 右侧指示内容出界
if (TP_value < -10) {boxPosition = [65, -120];
}leftColor = Gradient[Gradient.length - 1].color;
// 因为柱状初始化为0,温度存在负值,所以加上负值60和空出距离10option = {backgroundColor: '#0C2F6F',title: {text: '温度计',show: true,textStyle: {color: '#fff'}},yAxis: [{show: false,data: [],min: 0,max: 135,axisLine: {show: false}}, {show: false,min: 0,max: 50,}, {type: 'category',data: ['', '', '', '', '', '', '', '', '', '', '°C'],position: 'left',offset: -150,axisLabel: {fontSize: 18,color: 'white'},axisLine: {show: false},axisTick: {show: false},}],xAxis: [{show: false,min: -10,max: 80,data: []}, {show: false,min: -10,max: 80,data: []}, {show: false,min: -10,max: 80,data: []}, {show: false,min: -5,max: 80,}],series: [{name: '条/温度计柱',type: 'bar',// 对应上面XAxis的第一个对象配置xAxisIndex: 0,data: [{value: (showValue + 70),label: {normal: {show: true,position: boxPosition,backgroundColor: {image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAsT%0AAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNn%0AVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUc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G4ACXMPUtOVfVyB7IsdADFoVILy4srlpALW/Ixp%0AHQdgcfxn6vz5AajloG/dixgABXoHk172ebcKmPidmb7BSuvk4l+8AAiavOsg%0ArYpz/6qqN1j+/YEXhQV4s1qa/sUv8ScXmLN/zV+f/78BALa56loAiP6rAAAA%0AAElFTkSuQmCC', //文字框背景图},width: 100,height: 30,padding: [30, -40, 0, 0],formatter: '{back| ' + TP_value + ' }{unit|°C}\n{downTxt|' + TP_txt + '}',rich: {back: {align: 'right',lineHeight: 36,fontSize: 24,fontFamily: '微软雅黑',color: leftColor},unit: {align: 'right',fontFamily: '微软雅黑',fontSize: 14,lineHeight: 36,color: '#fff'},downTxt: {lineHeight: 36,fontSize: 24,align: 'right',color: leftColor}}}}}],barWidth: 20,itemStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 1, 0, 0, Gradient)}},z: 2}, {name: '白框/里面填充柱',type: 'bar',xAxisIndex: 1,barGap: '-100%',data: [134],barWidth: 28,itemStyle: {normal: {color: '#0C2E6D',barBorderRadius: 50,}},z: 1}, {name: '外框',type: 'bar',xAxisIndex: 2,barGap: '-100%',data: [135],barWidth: 38,itemStyle: {normal: {color: '#4577BA',barBorderRadius: 50,}},z: 0}, {name: '圆',type: 'scatter',hoverAnimation: false,data: [0],xAxisIndex: 0,symbolSize: 48,itemStyle: {normal: {color: '#93FE94',opacity: 1,}},z: 2}, {name: '白圆/温度计圆下方圆',type: 'scatter',hoverAnimation: false,data: [0],xAxisIndex: 1,symbolSize: 60,itemStyle: {normal: {color: '#0C2E6D',opacity: 1,}},z: 1}, {name: '外圆/最外层圆',type: 'scatter',hoverAnimation: false,data: [0],xAxisIndex: 2,symbolSize: 70,itemStyle: {normal: {color: '#4577BA',opacity: 1,}},z: 0}, {name: '刻度',type: 'bar',yAxisIndex: 0,xAxisIndex: 3,label: {normal: {show: true,position: 'left',distance: 10,color: 'white',fontSize: 14,formatter: function(params) {if (params.dataIndex > 130 || params.dataIndex < 10) {return '';} else {if ((params.dataIndex - 10) % 20 === 0) {return params.dataIndex - 70;} else {return '';}}}}},barGap: '-100%',data: kd,barWidth: 1,itemStyle: {normal: {color: 'white',barBorderRadius: 120,}},z: 0}]
};
总结
通过这个项目,我们了解了如何使用 ECharts 创建一个温度计的数字化呈现。ECharts 提供了丰富的图表类型和强大的交互功能,非常适合用于数据展示和分析。在未来的项目中,我们可以继续探索 ECharts 的其他功能和图表类型,以实现更多有趣和实用的数据可视化效果。