<template> <div class="chart-container"> <div class="chart-header"> <!--标题 --> <span class="title">订单统计</span> <el-select v-model="value" placeholder="请选择" size="mini"> <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" > </el-option> </el-select> </div> <div class="chart-content" :style="{ 'height': '300px', 'width': '500px' }"> <!-- echarts内容 --> <lineChart :seriesData="seriesData" :xAxisData="xAxisData"/> </div> </div> </template> <script> import lineChart from "../../../components/echart/lineChart/lineChart.vue"; import { getUserCountStatistic } from "@/api/cockpit/cockpit"; export default { name: "layoutChartSelect", components: { lineChart, }, props: { name: { type: String, default: "", }, width: { type: String, default: "500px", }, height: { type: String, default: "300px", }, }, data() { return { value: "year", options: [ { value: "year", label: "近一年", }, { value: "month", label: "近一月", }, ], xAxisData: [], yAxisData: [], seriesData: [], legend: [], }; }, mounted() { // this.fetchData(); setTimeout(() => { this.seriesData = [ { type:'line', name:'经销商订单数', data:[19,22,24,29,14,36,35] }, { type:'line', name:'分公司订单数', data:[11,32,29,29,44,31,15] } ] this.xAxisData = ['一月','二月','三月','四月','五月','六月','七月'] this.legend = ['经销商订单数','分公司订单数'] }, 2000); }, methods: { fetchData() { getUserCountStatistic(this.value).then((res) => { console.log(res.data, "订单统计"); // 图表数据 let seriesData = []; if (res.data.length > 0) { for (var user in res.data[0]) { legend.push(user); seriesData.push({ name: user, data: [], }); } } for (var i = 0; i < res.data.length; i++) { seriesData.forEach((item) => { if (item.name in res.data[i]) { item.data.push(res.data[i][item.name]); } }); } this.seriesData = seriesData.slice(1) this.xAxisData = seriesData.slice(0,1).data; }); }, }, }; </script> <style lang="scss" scoped> .chart-container { .chart-header { width: 500px; align-items: center; display: flex; justify-content: space-between; } } </style>