123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- <template>
- <div class="person_box">
- <div ref="chartDistrict" style="width: 100%;height: 100%;"></div>
- </div>
- </template>
- <script setup>
- import * as echarts from 'echarts'
- defineProps({
- title: {
- type: String,
- default: '暂无数据'
- }
- })
- const chartDistrict = ref(null);
- let chartDom = null;
- const initAccess = () => {
- let colorList = [
- "rgba(255, 38, 38, 1)",
- "rgba(255, 96, 0, 1)",
- "rgba(255, 165, 7, 1)",
- "rgba(0, 234, 255, 1)",
- "rgba(0, 132, 255, 1)",
- "#2379FF",
- ];
- let colorListA = [
- "rgba(255, 38, 38, 0.1)",
- "rgba(255, 96, 0, 0.1)",
- "rgba(255, 165, 7, 0.1)",
- "rgba(0, 234, 255, 0.1)",
- "rgba(0, 132, 255, 0.1)",
- "#49B1FF",
- ];
- let colorListB = [
- "rgba(249, 136, 136, 1)",
- "rgba(255, 162, 106, 1)",
- "rgba(255, 210, 130, 1)",
- "rgba(142, 255, 206, 1)",
- "rgba(165, 232, 255, 1)",
- ];
- let colorListC = [
- "rgba(249, 136, 136, 0.1)",
- "rgba(255, 162, 106, 0.1)",
- "rgba(255, 210, 130, 0.1)",
- "rgba(142, 255, 206, 0.1)",
- "rgba(165, 232, 255, 0.1)",
- ];
- let result = [
- { name: "天水祥丰农资农贸有限公司", value: 86 },
- { name: "天水花牛苹果", value: 83 },
- { name: "天水红富士", value: 73 },
- { name: "天水金帅苹果", value: 61 },
- { name: "天水黄面皮", value: 61 },
- ];
- chartDom = echarts.init(chartDistrict.value);
- let option = {
- color: colorList,
- tooltip: {
- show: true,
- trigger: "item",
- axisPointer: {
- type: "shadow",
- textStyle: {
- color: "#fff",
- },
- },
- textStyle: {
- color: "#fff",
- },
- backgroundColor: "rgba(16, 123, 184, .52)", //设置背景颜色
- borderColor: "rgba(255, 255, 255, 0)",
- confine: true,
- formatter: "{b}<br />客流指数: {c}",
- },
- legend: {
- show: false,
- },
- grid: {
- left: "2%",
- right: "2%",
- top: "6%",
- bottom: "0%",
- },
- xAxis: [
- {
- splitLine: {
- show: false,
- },
- type: "value",
- show: false,
- },
- ],
- yAxis: [
- {
- splitLine: {
- show: false,
- },
- axisLine: {
- show: false,
- },
- type: "category",
- axisTick: {
- show: false,
- },
- inverse: true,
- data: result.map((item) => item.name),
- axisLabel: {
- fontSize: 14,
- inside: true,
- formatter: (name, index) => {
- const id = index + 1;
- return `{count${id}|${id}}`;
- },
- rich: {
- count1: {
- padding: [0, 0, 33, 0],
- align: "center",
- color: colorList[0],
- fontSize: 14,
- fontFamily: "Source Han Sans CN",
- },
- count2: {
- padding: [0, 0, 33, 0],
- align: "center",
- color: colorList[1],
- fontSize: 14,
- fontFamily: "Source Han Sans CN",
- },
- count3: {
- padding: [0, 0, 33, 0],
- align: "center",
- color: colorList[2],
- fontSize: 14,
- fontFamily: "Source Han Sans CN",
- },
- count4: {
- padding: [0, 0, 33, 0],
- align: "center",
- color: colorList[3],
- fontSize: 14,
- fontFamily: "Source Han Sans CN",
- },
- count5: {
- padding: [0, 0, 33, 0],
- align: "center",
- color: colorList[4],
- fontSize: 14,
- fontFamily: "Source Han Sans CN",
- },
- },
- },
- },
- {
- type: "category",
- inverse: true,
- axisTick: "none",
- axisLine: "none",
- show: true,
- axisLabel: {
- textStyle: {
- color: "#fff",
- fontSize: 12,
- },
- verticalAlign: "bottom",
- padding: [0, 5, 10, 0],
- inside: true,
- formatter: function (value) {
- return `{name|客流指数:}{value|${value}}`;
- },
- rich: {
- name: {
- align: "center",
- color: "#D3E5FF",
- fontSize: 14,
- fontFamily: "Source Han Sans CN",
- },
- value: {
- align: "center",
- color: "#fff",
- fontSize: 14,
- fontFamily: "Source Han Sans CN",
- },
- },
- },
- data: result.map((item) => item.value),
- },
- ],
- series: [
- {
- name: "",
- type: "bar",
- barWidth: 5, // 柱子宽度
- MaxSize: 0,
- showBackground: true,
- barBorderRadius: [30, 0, 0, 30],
- backgroundStyle: {
- color: "rgba(50, 60, 86, 1)",
- },
- label: {
- show: true,
- offset: [40, -17],
- color: "#D3E5FF",
- fontWeight: 500,
- position: "left",
- align: "left",
- fontSize: 14,
- fontFamily: "Source Han Sans CN",
- formatter: function (params) {
- console.log(params);
- return params.data.name;
- },
- },
- data: result.map((item, index) => {
- return {
- name: item.name,
- value: item.value,
- itemStyle: {
- barBorderRadius: [3, 0, 0, 3],
- color: {
- type: "linear",
- x: 0,
- y: 0,
- x2: 1,
- y2: 1,
- colorStops: [
- {
- offset: 0,
- color: colorListA[index],
- },
- {
- offset: 1,
- color: colorList[index],
- },
- ],
- },
- },
- };
- }),
- },
- {
- name: "外圆",
- type: "scatter",
- emphasis: {
- scale: false,
- },
- showSymbol: true,
- symbol: "circle",
- symbolSize: 8, // 进度条白点
- z: 2,
- data: result.map((item, index) => {
- return {
- name: item.name,
- value: item.value,
- itemStyle: {
- color: colorListB[index],
- borderColor: colorListC[index],
- borderWidth: 12,
- shadowColor: colorListC[index],
- shadowBlur: 10,
- opacity: 1,
- },
- };
- }),
- animationDelay: 500,
- },
- {
- name: "外圆",
- type: "scatter",
- emphasis: {
- scale: false,
- },
- showSymbol: true,
- symbol: "circle",
- symbolSize: 3, // 进度条白点
- z: 3,
- data: result.map((item, index) => {
- return {
- name: item.name,
- value: item.value,
- itemStyle: {
- color: colorListB[index],
- borderColor: colorListC[index],
- borderWidth: 30,
- shadowColor: colorListC[index],
- shadowBlur: 10,
- opacity: 1,
- },
- };
- }),
- animationDelay: 500,
- },
- ],
- };
- chartDom.setOption(option)
- };
- // 生命周期
- onMounted(() => {
- initAccess()
- });
- // 窗口自适应
- window.addEventListener('resize', () => {
- chartDom?.resize();
- });
- </script>
- <style scoped lang="scss">
- .person_box {
- width: 100%;
- height: 100%;
- display: flex;
- align-items: center;
- }
- </style>
|