<template>
<div class="datalist">
<!-- 数据报表容器 -->
<div id="main" style="width: 750px; height: 400px"></div>
</div>
</template>
<script>
//引入echarts图表
import * as echarts from "echarts";
import { getReports } from "@/api/api.js";
import _ from "lodash";
export default {
data() {
return {
option: {
title: {
text: "用户来源", //标题
left: "left", //方位
},
tooltip: {
trigger: "axis", //坐标轴触发
axisPointer: {
//坐标轴指针显示
type: "cross", //类型为十字
label: {
backgroundColor: "#E9EEF3", //显示坐标轴信息的背景颜色
},
},
},
grid: {
//栅格
left: "3%",
right: "4%",
bottom: "3%",
containLabel: true,
},
xAxis: [
//x坐标轴
{
boundaryGap: false,
},
],
yAxis: [
//y坐标轴
{
type: "value",
},
],
},
};
},
async mounted() {
var chartDom = document.getElementById("main"); //获取元素节点
let { data: res } = await getReports(); //请求数据
// console.log(res.data);
if (res.meta.status !== 200) return this.$message("获取折线图数据失败!");
var myChart = echarts.init(chartDom); //初始化实例
const result = _.merge(res.data, this.option); //合并请求过来的数据
// console.log(result);
myChart.setOption(result); //展示数据
},
methods: {},
components: {},
};
</script>
<style lang="scss" scoped>
.datalist {
width: 100%;
height: 100%;
box-sizing: border-box;
padding: 20px;
}
</style>