|
@@ -0,0 +1,193 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <el-row :gutter="5">
|
|
|
+ <el-col :span="8">
|
|
|
+ <div style="display: flex;">
|
|
|
+ <!--<span>{{ modelValue }}</span>-->
|
|
|
+ <TextSelector :modelValue="modelValue" :options="options" style="margin-top: 5px"/>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div id="pie" style="height: 400px;"></div>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="16">
|
|
|
+ <div id="bar" style="height: 400px;"></div>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { onMounted, ref } from "vue"
|
|
|
+import * as echarts from "echarts"
|
|
|
+import TextSelector from '/@/components/TextSelector/index.vue'
|
|
|
+
|
|
|
+let pieChart = ref()
|
|
|
+let barChart = ref()
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ pieChart = echarts.init(document.getElementById('pie'))
|
|
|
+ barChart = echarts.init(document.getElementById('bar'))
|
|
|
+ setChartData()
|
|
|
+ window.addEventListener('resize', resizeChart) // 监听窗口大小变化,调整图表大小
|
|
|
+ setTimeout(() => {
|
|
|
+ resizeChart()
|
|
|
+ }, 0)
|
|
|
+
|
|
|
+})
|
|
|
+
|
|
|
+function setChartData() {
|
|
|
+ // 柱状图配置
|
|
|
+ const option = {
|
|
|
+ tooltip: {
|
|
|
+ trigger: 'axis',
|
|
|
+ axisPointer: {
|
|
|
+ type: 'cross',
|
|
|
+ label: {
|
|
|
+ backgroundColor: '#6a7985'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ legend: {data: ['数据1', '数据2'],},
|
|
|
+ toolbox: {
|
|
|
+ feature: {
|
|
|
+ saveAsImage: { yAxisIndex: 'none' }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ grid: {
|
|
|
+ top: 70, right: 60, bottom: 30, left: 55,
|
|
|
+
|
|
|
+ },
|
|
|
+ xAxis: [
|
|
|
+ {
|
|
|
+ type: 'category',
|
|
|
+ boundaryGap: true,
|
|
|
+ data: ['商品', '品类', '关键词-精准', '关键词-广泛', '关键词-词组'],
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ yAxis: [
|
|
|
+ {
|
|
|
+ type: 'value',
|
|
|
+ name: '数据1',
|
|
|
+ axisLabel: {
|
|
|
+ formatter: '{value} 单位1'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'value',
|
|
|
+ name: '数据2',
|
|
|
+ splitLine: {
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ axisLabel: {
|
|
|
+ formatter: '{value} 单位2'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ series: [
|
|
|
+ {
|
|
|
+ name: '数据1',
|
|
|
+ type: 'bar',
|
|
|
+ // tooltip: {
|
|
|
+ // valueFormatter: function (value) {
|
|
|
+ // return value + ' ml';
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ barWidth: '30%',
|
|
|
+ data: [2, 24, 21, 40, 51],
|
|
|
+ yAxisIndex: 0,
|
|
|
+ itemStyle: {
|
|
|
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
+ { offset: 0, color: 'rgba(111, 209, 206, 0.8)' },
|
|
|
+ { offset: 1, color: 'rgba(111, 209, 206, 0.1)' },
|
|
|
+ ]),
|
|
|
+ //柱状图圆角
|
|
|
+ borderRadius: [15, 15, 0, 0],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '数据2',
|
|
|
+ type: 'bar',
|
|
|
+ barWidth: '30%',
|
|
|
+ data: [10, 20, 30, 40, 50],
|
|
|
+ yAxisIndex: 1,
|
|
|
+ itemStyle: {
|
|
|
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
+ { offset: 0, color: '#ebb14d' },
|
|
|
+ { offset: 1, color: 'rgba(111, 209, 206, 0.1)' },
|
|
|
+ ]),
|
|
|
+ //柱状图圆角
|
|
|
+ borderRadius: [15, 15, 0, 0],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ }
|
|
|
+ barChart.setOption(option)
|
|
|
+ // 饼图配置
|
|
|
+ const option2 = {
|
|
|
+ tooltip: {
|
|
|
+ trigger: 'item'
|
|
|
+ },
|
|
|
+ series: [
|
|
|
+ {
|
|
|
+ name: 'Access From',
|
|
|
+ type: 'pie',
|
|
|
+ radius: ['40%', '70%'],
|
|
|
+ avoidLabelOverlap: false,
|
|
|
+ label: {
|
|
|
+ show: false,
|
|
|
+ position: 'center'
|
|
|
+ },
|
|
|
+ emphasis: {
|
|
|
+ label: {
|
|
|
+ show: true,
|
|
|
+ fontSize: 40,
|
|
|
+ fontWeight: 'bold'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ labelLine: {
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ data: [
|
|
|
+ { value: 1048, name: 'Search Engine' },
|
|
|
+ { value: 735, name: 'Direct' },
|
|
|
+ { value: 580, name: 'Email' },
|
|
|
+ { value: 484, name: 'Union Ads' },
|
|
|
+ { value: 300, name: 'Video Ads' }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ pieChart.setOption(option2)
|
|
|
+ resizeChart()
|
|
|
+}
|
|
|
+
|
|
|
+function resizeChart() {
|
|
|
+ if (barChart) {
|
|
|
+ barChart.resize()
|
|
|
+ pieChart.resize()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+defineExpose({ resizeChart })
|
|
|
+
|
|
|
+// 下拉框相关
|
|
|
+const options = [
|
|
|
+ {
|
|
|
+ value: 'Option1',
|
|
|
+ label: 'Option1',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 'Option2',
|
|
|
+ label: 'Option2',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 'Option3',
|
|
|
+ label: 'Option3',
|
|
|
+ }
|
|
|
+]
|
|
|
+const modelValue = ref(options[0].value)
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+
|
|
|
+</style>
|