feat: 整合echarts,添加柱状图、饼图、漏斗和雷达图

This commit is contained in:
郝先瑞
2022-01-24 00:38:22 +08:00
parent d02a8e27ce
commit 35ceddc39a
8 changed files with 501 additions and 342 deletions

View File

@@ -0,0 +1,143 @@
<!-- 柱状图 -->
<template>
<div
:id="id"
:class="className"
:style="{height, width}"
/>
</template>
<script setup lang="ts">
import {nextTick, onMounted} from "vue";
import {init, EChartsOption} from 'echarts'
const props = defineProps({
id: {
type: String,
default: 'barChart'
},
className: {
type: String,
default: ''
},
width: {
type: String,
default: '200px',
required: true
},
height: {
type: String,
default: '200px',
required: true
}
})
function initChart() {
const barChart = init(document.getElementById(props.id) as HTMLDivElement)
barChart.setOption({
title: {
show: true,
text: '分公司业绩总览(2021年财报)',
x: 'center',
padding: 15,
textStyle: {
fontSize: 18,
fontStyle: 'normal',
fontWeight: 'bold',
color:'#096b92'
}
},
grid: {
left: '2%',
right: '2%',
bottom: '10%',
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
crossStyle: {
color: '#999'
}
}
},
legend: {
x: 'center',
y: 'bottom',
data: ['收入', '毛利润', '收入增长率', '利润增长率']
},
xAxis: [
{
type: 'category',
data: ['上海', '北京', '浙江', '广东', '深圳', '四川', '湖北', '安徽', '湖南', '山东','海外'],
axisPointer: {
type: 'shadow'
}
}
],
yAxis: [
{
type: 'value',
min: 0,
max: 10000,
interval: 2000,
axisLabel: {
formatter: '{value} '
}
},
{
type: 'value',
min: 0,
max: 100,
interval: 20,
axisLabel: {
formatter: '{value}%'
}
}
],
series: [
{
name: '收入',
type: 'bar',
data: [
8000, 8200, 7000, 6200, 6500, 5500, 4500, 4200, 3800, 4200, 6700, 5213
],
barWidth : 20
},
{
name: '毛利润',
type: 'bar',
data: [
6200, 6500, 5500, 4500, 4200, 3800, 4200, 6700, 5213, 8000,8200, 7000
],
barWidth : 20
},
{
name: '收入增长率',
type: 'line',
yAxisIndex: 1,
data: [42, 41, 53, 65, 67, 65, 52, 45, 43, 54, 42,46]
},
{
name: '利润增长率',
type: 'line',
yAxisIndex: 1,
data: [82, 81, 56, 45, 51, 65, 65, 67, 78, 76, 67, 78]
}
]
})
}
onMounted(() => {
nextTick(() => {
initChart()
})
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,118 @@
<!-- 漏斗图 -->
<template>
<div
:id="id"
:class="className"
:style="{height, width}"
/>
</template>
<script setup lang="ts">
import {nextTick, onMounted} from "vue";
import {init, EChartsOption} from 'echarts'
const props = defineProps({
id: {
type: String,
default: 'funnelChart'
},
className: {
type: String,
default: ''
},
width: {
type: String,
default: '200px',
required: true
},
height: {
type: String,
default: '200px',
required: true
}
})
function initChart() {
const pieChart = init(document.getElementById(props.id) as HTMLDivElement)
pieChart.setOption({
title: {
show: true,
text: '订单线索转化漏斗图',
x: 'center',
padding: 15,
textStyle: {
fontSize: 18,
fontStyle: 'normal',
fontWeight: 'bold',
color:'#096b92'
}
},
grid: {
left: '2%',
right: '2%',
bottom: '10%',
containLabel: true
},
legend: {
x: 'center',
y: 'bottom',
data: ['Show', 'Click', 'Visit', 'Inquiry', 'Order']
},
series: [
{
name: 'Funnel',
type: 'funnel',
left: '20%',
top: 60,
bottom: 60,
width: '60%',
min: 0,
max: 100,
minSize: '0%',
maxSize: '100%',
sort: 'descending',
gap: 2,
label: {
show: true,
position: 'inside'
},
labelLine: {
length: 10,
lineStyle: {
width: 1,
type: 'solid'
}
},
itemStyle: {
borderColor: '#fff',
borderWidth: 1
},
emphasis: {
label: {
fontSize: 20
}
},
data: [
{ value: 60, name: 'Visit' },
{ value: 40, name: 'Inquiry' },
{ value: 20, name: 'Order' },
{ value: 80, name: 'Click' },
{ value: 100, name: 'Show' }
]
}
]
})
}
onMounted(() => {
nextTick(() => {
initChart()
})
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,94 @@
<!-- 饼图 -->
<template>
<div
:id="id"
:class="className"
:style="{height, width}"
/>
</template>
<script setup lang="ts">
import {nextTick, onMounted} from "vue";
import {init, EChartsOption} from 'echarts'
const props = defineProps({
id: {
type: String,
default: 'pieChart'
},
className: {
type: String,
default: ''
},
width: {
type: String,
default: '200px',
required: true
},
height: {
type: String,
default: '200px',
required: true
}
})
function initChart() {
const pieChart = init(document.getElementById(props.id) as HTMLDivElement)
pieChart.setOption({
title: {
show: true,
text: '产品品类分部总览南丁格尔饼图',
x: 'center',
padding: 15,
textStyle: {
fontSize: 18,
fontStyle: 'normal',
fontWeight: 'bold',
color:'#096b92'
}
},
grid: {
left: '2%',
right: '2%',
bottom: '10%',
containLabel: true
},
legend: {
top: 'bottom'
},
series: [
{
name: 'Nightingale Chart',
type: 'pie',
radius: [50, 180],
center: ['50%', '50%'],
roseType: 'area',
itemStyle: {
borderRadius: 8
},
data: [
{ value: 22, name: 'rose 1' },
{ value: 24, name: 'rose 2' },
{ value: 32, name: 'rose 3' },
{ value: 30, name: 'rose 4' },
{ value: 28, name: 'rose 5' },
{ value: 26, name: 'rose 6' },
{ value: 22, name: 'rose 7' },
{ value: 18, name: 'rose 8' }
]
}
]
})
}
onMounted(() => {
nextTick(() => {
initChart()
})
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,101 @@
<!-- 雷达图 -->
<template>
<div
:id="id"
:class="className"
:style="{height, width}"
/>
</template>
<script setup lang="ts">
import {nextTick, onMounted} from "vue";
import {init, EChartsOption} from 'echarts'
const props = defineProps({
id: {
type: String,
default: 'radarChart'
},
className: {
type: String,
default: ''
},
width: {
type: String,
default: '200px',
required: true
},
height: {
type: String,
default: '200px',
required: true
}
})
function initChart() {
const pieChart = init(document.getElementById(props.id) as HTMLDivElement)
pieChart.setOption({
title: {
show: true,
text: '订单状态总雷达图',
x: 'center',
padding: 15,
textStyle: {
fontSize: 18,
fontStyle: 'normal',
fontWeight: 'bold',
color:'#096b92'
}
},
grid: {
left: '2%',
right: '2%',
bottom: '10%',
containLabel: true
},
legend: {
x: 'center',
y: 'bottom',
data: ['待支付', '已发货']
},
radar: {
// shape: 'circle',
indicator: [
{ name: 'Sales', max: 6500 },
{ name: 'Administration', max: 16000 },
{ name: 'Information Technology', max: 30000 },
{ name: 'Customer Support', max: 38000 },
{ name: 'Development', max: 52000 },
{ name: 'Marketing', max: 25000 }
]
},
series: [
{
name: 'Budget vs spending',
type: 'radar',
data: [
{
value: [4200, 3000, 20000, 35000, 50000, 18000],
name: '待支付'
},
{
value: [5000, 14000, 28000, 26000, 42000, 21000],
name: '已发货'
}
]
}
]
})
}
onMounted(() => {
nextTick(() => {
initChart()
})
})
</script>
<style lang="scss" scoped>
</style>