当前位置: 首页 > news >正文

徐州市贾汪区建设局网站网站建设前期需要准备什么资料

徐州市贾汪区建设局网站,网站建设前期需要准备什么资料,邢台做网站的,黄页推广网站下载概述 技术栈:Vue3TsViteEcharts 简述:图文详解,教你如何在Vue项目中引入Echarts,封装Echarts组件,并实现常用Echats图列 文章目录 一,效果图 二,引入Echarts 2.1安装Echarts 2.2main.ts中引…

概述

技术栈:Vue3+Ts+Vite+Echarts

简述:图文详解,教你如何在Vue项目中引入Echarts,封装Echarts组件,并实现常用Echats图列


文章目录

一,效果图

二,引入Echarts

        2.1安装Echarts

        2.2main.ts中引入

        2.3Echarts组件封装

三,使用

        3.1柱形图(为例)


文章正文

一效果图

静态效果

动态效果

    2.1安装Echarts

2.1.1 npm

npm i echarts --save

2.2.2 pnpm

pnpm i echarts -s

2.2main.ts中引入

//引入echarts
import * as echarts from 'echarts'
app.config.globalProperties.$echarts = echarts;

2.3Echarts组件封装

在/src/components/echartsComp.vue文件中写入以下代码


<template><div ref="myChartsRef" :style="{ height: height, width: width }" :option="option" />
</template><script setup lang="ts">
import { ECharts, EChartsOption, init } from 'echarts';
import { ref, watch, onMounted, onBeforeUnmount } from 'vue';// 定义props泛型
interface Props {width?: string;height?: string;option: EChartsOption;
}
const props = withDefaults(defineProps<Props>(), {width: '100%',height: '100%',option: () => ({})
});const myChartsRef = ref<HTMLDivElement>();
let myChart: ECharts;
// eslint-disable-next-line no-undef
let timer: string | number | NodeJS.Timeout | undefined;// 初始化echarts
const initChart = (): void => {if (myChart !== undefined) {myChart.dispose();}myChart = init(myChartsRef.value as HTMLDivElement);// 拿到option配置项,渲染echartsmyChart?.setOption(props.option, true);
};// 重新渲染echarts
const resizeChart = (): void => {timer = setTimeout(() => {if (myChart) {myChart.resize();}}, 50);
};
// 挂载
onMounted(() => {initChart();window.addEventListener('resize', resizeChart);
});
// 挂载前
onBeforeUnmount(() => {window.removeEventListener('resize', resizeChart);clearTimeout(timer);timer = 0;
});// 监听器
watch(props.option,() => {initChart();},{deep: true}
);
</script>

三,使用(以柱状图为例)

效果图

1,在需要的组件中引入该封装的组件

2,在需要的位置引入该组件

<template><div class="common-layout"><el-main><div :style="{ width: '100%', height: '100%' }"><Echarts :option="option" /></div></el-main></div>
</template><script setup lang="ts">
//引入ref实现响应式数据
import { reactive ,ref} from 'vue';
// 引入封装好的组件
import Echarts from '../components/echartsComp.vue';const option =  reactive({backgroundColor: '#fff',title:{text:'数据统计',align: 'center',},grid: {containLabel: true,bottom: '5%',top: '20%',left: '5%',right: '5%',},tooltip: {trigger: 'axis',axisPointer: {type: 'shadow',},},legend: {top: '10%',right: '40%',data: ['订单', '销售额'],itemWidth: 18,itemHeight: 18,itemGap: 30,textStyle: {fontSize: 10,color: 'black',padding: [0, 0, 0, 10],},},xAxis: {// name: "班级",triggerEvent: true,data: ['2023/05/17', '2023/05/18', '2023/03/19', '2023/05/19', '2023/05/20', '2023/05/21', '2023/05/22'],axisLabel: {show: true,fontSize: 14,color: '#C9D2FA',rotate: 10, // 设置旋转角度为30度align: 'right', verticalAlign: 'top',},axisLine: {show: false,lineStyle: {show: false,color: '#F3F3F3',width: 2,},},axisTick: {show: false,},},yAxis: [{// name: '单位:万',// type: 'value',// nameTextStyle: {//   color: '#444444',// },axisLabel: {interval: 0,show: true,fontSize: 18,color: '#C9D2FA',},axisLine: {show: false,// lineStyle: {//   color: "#F3F3F3",//   width: 2// }},axisTick: {show: false,},splitLine: {lineStyle: {type: 'dashed',color: '#3E4A82',},},},],series: [{name: '订单',type: 'bar',align: 'center',silent: true,itemStyle: {normal: {color: '#2F8FFF',},},label: {show: true,color: '#2F8FFF',fontSize: 14,position: 'top', // 显示位置,可选值有 'top', 'bottom', 'inside', 'outside'formatter: '{c}', // 标签内容格式器,这里表示显示数据值},data: [120, 75, 90, 102, 130, 75, 99],},{name: '销售额',type: 'bar',silent: true,itemStyle: {normal: {color: '#47B558',},},label: {show: true,color: '#47B558',fontSize: 14,position: 'top', // 显示位置,可选值有 'top', 'bottom', 'inside', 'outside'formatter: '{c}', // 标签内容格式器,这里表示显示数据值},data: [102, 130, 75, 99, 120, 75, 90],},],})
</script>

http://www.yayakq.cn/news/63560/

相关文章:

  • 网站建设英文翻译成品门户网站源码免费
  • 太原网站建设制作公司哪家好注册百度推广账号
  • 网站建设图书xunsearch做搜索网站
  • 南宁网站建设方案服务怎样做才能发布你的网站
  • 家教网站建设营销网站建设哪里便宜
  • 怎么办一个网站wordpress+登录+api接口
  • 重庆推广网站的方法the 7 wordpress
  • 一般自己怎么做网站好的家装设计
  • 网页qq登陆网站盐城网站app建设
  • 苏州市住房和城乡建设局信息网站龙岗区教育局
  • 个人网站建设的小清新图片温州网站网络公司
  • 网站开发接私活的经理wordpress无插件自动实现tag关键字内链
  • 网站建设 年终总结搭建科技网站价格
  • 网站会员系统怎么做网站识别手机电脑自动跳转
  • 服务好的高端网站建设公司自己设计家装的app
  • 设计的网站有哪些wordpress自定义上传头像
  • 宜昌做网站的北京建设执业注册中心网站
  • 交通网站建设广东省建设网官网
  • 校园网站建设规划书网站页眉设计
  • 做一个电商网站要多少钱资中做网站多少钱
  • 相城区住房建设局网站杭州旅游攻略
  • 应不应该购买老域名建设新网站暗网网站
  • 百度推广网站备案荣耀手机正品官网查询
  • 大连网站如何制作网易云音乐wordpress插件下载
  • 台州网站建设平台义乌网站制作是什么
  • 工信部icp网站备案查询玮科网站建设
  • 北京国互网网站建设报价网站建设服务专业建站公司
  • 重庆建设工程安全管理局网站手车做网课网站
  • div使用太多影响网站收录创建全国文明城市的目的
  • 免费的网站怎么做现在推广引流什么平台比较火