<Echart :echartIndex="1" :data="dataList?.download_range" />
import { defineComponent, onMounted, ref, computed, ComputedRef } from "vue";
import * as echarts from "echarts";
import { times, parseTime } from "../../utils/auth";
export default defineComponent({
props: {
echartIndex: {
type: Number,
},
data: {
type: Array,
},
},
setup({ echartIndex, data }: any) {
console.log("12331213", data);
const getTodo = computed(() => (e: any) => {
return times(e);
});
const getTime = computed(() => (e: any) => {
return parseTime(e, "{y}-{m}-{d} {h}:{i}:{s}");
});
const echart = ref<HTMLElement>();
const initEcharts = () => {
const ehartInstance = echarts.init(echart.value);
const xTime = data[0].range.map((item: any) =>
parseTime(item.time, "{h}:{i}:{s}")
);
const colorStop = [
[
{ offset: 0, color: "rgba(38,215,169,0.00)" },
{ offset: 1, color: "rgba(38,215,169,0.50)" },
],
[
{ offset: 0, color: "rgba(100,157,235,0.00)" },
{ offset: 1, color: "rgba(100,157,235,0.50)" },
],
];
var itemStyles = {
color: "#26D7A9",
borderColor: "#26D7A9",
borderWidth: 3,
shadowColor: "#26D7A9",
shadowBlur: 1,
};
var lineStyles = [
{ color: "rgba(38,215,169,0.8)" },
{ color: "rgba(100,157,235,0.8)" },
];
const series = data.map((item: any, index: any) => {
return {
type: "line",
name: item.device,
data: item.range.map((r: any) => Number(r.value).toFixed(3)),
stack: "Total",
showSymbol: false,
itemStyle: {
color: lineStyles[index].color,
borderColor: lineStyles[index].color,
borderWidth: 3,
},
lineStyle: lineStyles[index],
areaStyle: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
colorStop[index]
),
},
};
});
console.log(series);
const options = {
tooltip: {
trigger: "axis",
},
legend: {},
xAxis: {
type: "category",
data: xTime,
},
yAxis: {
type: "value",
},
series: series,
};
options && ehartInstance.setOption(options);
};
onMounted(() => {
if (data) {
initEcharts();
}
});
return {
echart,
echartIndex,
getTime,
parseTime,
};
},
});