123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <template>
- <div class="thermometer"></div>
- </template>
- <script>
- import * as echarts from "echarts";
- export default {
- // 名称
- name: "thermometer",
- // 使用组件
- components: {},
- // 传入参数
- props: {
- width: {
- type: String,
- default: "9.259vh",
- },
- height: {
- type: String,
- default: "11.111vh",
- },
- min: {
- type: Number,
- default: -20,
- },
- max: {
- type: Number,
- default: 100,
- },
- value: {
- type: Number,
- default: 36.6,
- },
- title: {
- type: String,
- default: "温度",
- },
- },
- // 自定义事件
- emits: {},
- // 数据
- data() {
- return {
- option: {},
- };
- },
- // 函数
- methods: {
- initChart: function() {
- const chart = echarts.init(this.$el);
- let kd = []; // 刻度
- for (var i = 0, len = 135; i <= len; i++) {
- if (i < 30 || i > 130) {
- kd.push("");
- } else {
- if ((i - 30) % 20 === 0) {
- kd.push("-3");
- } else if ((i - 30) % 4 === 0) {
- kd.push("-1");
- } else {
- kd.push("");
- }
- }
- }
- let width = this.$el.offsetWidth;
- this.option = {
- backgroundColor: "transparent",
- grid: {
- top: "0",
- left: "0",
- right: "0",
- bottom: "45%",
- },
- yAxis: [
- {
- axisLine: {
- show: false,
- },
- axisLabel: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- },
- {
- show: false,
- data: [],
- min: 0,
- max: 135,
- axisLine: {
- show: false,
- },
- },
- ],
- xAxis: [
- {
- axisTick: "none",
- axisLine: "none",
- offset: 0,
- data: [this.title],
- axisLabel: {
- show: true,
- textStyle: {
- color: "#606769",
- fontSize: "14",
- },
- lineHeight: 40,
- },
- splitLine: {
- show: false,
- },
- },
- {
- axisTick: "none",
- axisLabel: {
- show: false,
- },
- data: [0],
- splitLine: {
- show: false,
- },
- axisLine: {
- show: false,
- },
- },
- {
- name: "单位:件",
- nameGap: "50",
- data: [],
- splitLine: {
- show: false,
- },
- axisLine: {
- show: false,
- color: "#ffffff",
- },
- },
- {
- show: false,
- min: 0 - width * 0.35,
- max: width * 0.5,
- },
- ],
- series: [
- {
- name: "℃",
- type: "bar",
- yAxisIndex: 0,
- xAxisIndex: 0,
- label: {
- show: true,
- position: "top",
- formatter: "{back|" + "{c}" + "}",
- rich: {
- back: {
- align: "right",
- lineHeight: 14,
- fontSize: 14,
- fontFamily: "微软雅黑",
- color: "#05bb4c",
- },
- },
- offset: [25, 15],
- },
- data: [this.value],
- barWidth: 5,
- itemStyle: {
- normal: {
- color: "#05bb4c",
- },
- },
- z: 2,
- },
- {
- name: "温度背景框",
- type: "bar",
- yAxisIndex: 0,
- xAxisIndex: 1,
- barGap: "-100%",
- data: [99],
- barWidth: 8,
- itemStyle: {
- normal: {
- color: "#040c0b",
- barBorderRadius: 5,
- },
- },
- z: 1,
- },
- {
- name: "外框",
- type: "bar",
- yAxisIndex: 0,
- xAxisIndex: 2,
- barGap: "-100%",
- data: [100],
- barWidth: width * 0.1,
- itemStyle: {
- normal: {
- color: "#606769",
- barBorderRadius: width * 0.5,
- },
- },
- z: 0,
- },
- {
- name: "外圆",
- type: "scatter",
- hoverAnimation: false,
- data: [0],
- yAxisIndex: 0,
- xAxisIndex: 2,
- symbolSize: width * 0.15,
- itemStyle: {
- normal: {
- color: "#05bb4c",
- opacity: 1,
- },
- },
- z: 2,
- },
- {
- name: "白圆",
- type: "scatter",
- hoverAnimation: false,
- data: [0],
- yAxisIndex: 0,
- xAxisIndex: 1,
- symbolSize: width * 0.2,
- itemStyle: {
- normal: {
- color: "#040c0b",
- opacity: 1,
- },
- },
- z: 1,
- },
- {
- name: "外圆",
- type: "scatter",
- hoverAnimation: false,
- data: [0],
- yAxisIndex: 0,
- xAxisIndex: 2,
- symbolSize: width * 0.23,
- itemStyle: {
- normal: {
- color: "#606769",
- opacity: 1,
- },
- },
- z: 0,
- },
- {
- name: "刻度",
- type: "bar",
- yAxisIndex: 1,
- xAxisIndex: 3,
- label: {
- normal: {
- show: false,
- },
- },
- barGap: "100%",
- data: kd,
- barWidth: 1,
- itemStyle: {
- normal: {
- color: "#606769",
- barBorderRadius: width * 1.2,
- },
- },
- z: 0,
- },
- ],
- };
- chart.setOption(this.option);
- },
- setValue: function() {
- this.option.series[0].data[0] = this.value;
- const chart = echarts.getInstanceByDom(this.$el);
- chart.setOption(this.option);
- },
- },
- // 生命周期钩子
- beforeCreate() {
- // 创建前
- },
- created() {
- // 创建后
- },
- beforeMount() {
- // 渲染前
- },
- mounted() {
- // 渲染后
- this.$nextTick(() => {
- this.$el.style.width = this.width;
- this.$el.style.height = this.height;
- this.initChart();
- });
- },
- beforeUpdate() {
- // 数据更新前
- },
- updated() {
- // 数据更新后
- this.setValue();
- },
- };
- </script>
- <style lang="less">
- .thermometer {
- }
- </style>
|