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

Vue2实战场景:图表组件 + Grid 布局

echarts下载

npm install echarts

图表组件

代码

src\components\Charts\MyBarChart.vue

<template><div ref="chartRef" class="chart-container"></div>
</template><script>
import * as echarts from "echarts/core";
import { GridComponent } from "echarts/components";
import { BarChart } from "echarts/charts";
import { CanvasRenderer } from "echarts/renderers";echarts.use([GridComponent, BarChart, CanvasRenderer]);
let resizeTimer = null;
export default {name: "BarChart",props: {theme: {type: String,default: "light",},},data() {return {chartInstance: null,};},mounted() {this.$nextTick(() => {setTimeout(() => {this.initChart();window.addEventListener("resize", () => {clearTimeout(resizeTimer);resizeTimer = setTimeout(() => {this.chartInstance.resize();}, 200); // ✅ 200ms后执行,用户停止拖动才触发});}, 300);});},beforeDestroy() {window.removeEventListener("resize", this.resizeChart);if (this.chartInstance) {this.chartInstance.dispose();}},methods: {initChart() {this.chartInstance = echarts.init(this.$refs.chartRef, this.theme);const option = {toolbox: {feature: {saveAsImage: {},},},grid: {left: "20px",right: "20px",top: "40px",bottom: "40px",},xAxis: {type: "category",data: ["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月",],},yAxis: {type: "value",},series: [{data: [120, 200, 150, 80, 70, 110, 130, 160, 180, 140, 100, 90],type: "bar",},],};this.chartInstance.setOption(option);},resizeChart() {if (this.chartInstance) {this.chartInstance.resize();}},},
};
</script><style scoped>
.chart-container {width: 100%;height: 100%;
}
</style>

src\components\Charts\MyLineChart.vue

<template><div ref="chartRef" class="chart-container"></div>
</template><script>
import * as echarts from "echarts/core";
import {TitleComponent,ToolboxComponent,TooltipComponent,GridComponent,LegendComponent,
} from "echarts/components";
import { LineChart } from "echarts/charts";
import { UniversalTransition } from "echarts/features";
import { CanvasRenderer } from "echarts/renderers";echarts.use([TitleComponent,ToolboxComponent,TooltipComponent,GridComponent,LegendComponent,LineChart,CanvasRenderer,UniversalTransition,
]);
let resizeTimer = null;
export default {name: "LineChart",props: {theme: {type: String,default: "light",},},data() {return {chartInstance: null,};},mounted() {this.$nextTick(() => {setTimeout(() => {this.initChart();window.addEventListener("resize", () => {clearTimeout(resizeTimer);resizeTimer = setTimeout(() => {this.chartInstance.resize();}, 200); // ✅ 200ms后执行,用户停止拖动才触发});}, 300);});},beforeDestroy() {window.removeEventListener("resize", this.resizeChart);if (this.chartInstance) {this.chartInstance.dispose();}},methods: {initChart() {this.chartInstance = echarts.init(this.$refs.chartRef, this.theme);const option = {grid: {left: "0px",right: "0px",top: "60px",bottom: "60px",},tooltip: {trigger: "axis",axisPointer: {type: "cross",label: {backgroundColor: "#6a7985",},},},legend: {data: ["Email", "Union Ads", "Video Ads", "Direct", "Search Engine"],},toolbox: {feature: {saveAsImage: {},},},xAxis: [{type: "category",boundaryGap: false,data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],},],yAxis: [{type: "value",},],series: [{name: "Email",type: "line",stack: "Total",areaStyle: {},emphasis: { focus: "series" },data: [120, 132, 101, 134, 90, 230, 210],},{name: "Union Ads",type: "line",stack: "Total",areaStyle: {},emphasis: { focus: "series" },data: [220, 182, 191, 234, 290, 3

文章转载自:

http://S6fiUklE.Lfmwt.cn
http://lqf06pla.Lfmwt.cn
http://pCA11I0F.Lfmwt.cn
http://qq6NTQGm.Lfmwt.cn
http://gOeKYjcd.Lfmwt.cn
http://TWuDV6cZ.Lfmwt.cn
http://sHpZSI5G.Lfmwt.cn
http://SXYgZQHj.Lfmwt.cn
http://N9L7uX4K.Lfmwt.cn
http://zkdLupac.Lfmwt.cn
http://isqaAlL5.Lfmwt.cn
http://GdLdNs5h.Lfmwt.cn
http://kST01htN.Lfmwt.cn
http://DXGbujU0.Lfmwt.cn
http://7kLI4LWi.Lfmwt.cn
http://qNlXkyuA.Lfmwt.cn
http://X4k8c4z2.Lfmwt.cn
http://M5mZ4xMI.Lfmwt.cn
http://XKRGy8dv.Lfmwt.cn
http://opgvzJ8k.Lfmwt.cn
http://qZYVXsjN.Lfmwt.cn
http://p0wbIGcO.Lfmwt.cn
http://79VrjK56.Lfmwt.cn
http://aRl3mTOj.Lfmwt.cn
http://zBOcyURf.Lfmwt.cn
http://iz5ilHXo.Lfmwt.cn
http://4DJGhqsG.Lfmwt.cn
http://EtHeRzor.Lfmwt.cn
http://Od5uU921.Lfmwt.cn
http://ASVRIGkE.Lfmwt.cn
http://www.dtcms.com/a/386324.html

相关文章:

  • Linux:基于阻塞队列的生产者消费模型
  • springboot+vue (ruoyi-vue前后端分离)集成钉钉登录
  • 从单一辅助到深度协作!GPT-5-Codex 改写软件开发工作流
  • JavaScript——document对象
  • 图观 流渲染场景编辑器
  • 探索大语言模型(LLM):Windows系统与Linux系统下的Ollama高级配置(修改模型地址、Service服务以及多卡均衡调用)
  • PowerBI实战-制作带有同比及趋势线的双柱状图
  • Spring 介绍
  • 使用爱思助手(版本8.16)将ipa安装到ios
  • 大模型应用开发2-SpringAI实战
  • 【面板数据】上市公司校企合作论文发表数据集(2002-2025年)
  • MySQL的底层数据结构:B+树
  • 【Linux】LRU缓存(C++模拟实现)
  • 冲击成本敏感度曲线驱动的拆单频率参数动态调优机制
  • Typera+Gitee+PicGo 配置markdown专用图床
  • 正则化:机器学习泛化能力的守护神
  • GCKontrol对嵌入式设备FPGA设计流程的高效优化
  • vue2+vue3-自定义指令
  • Vue基础知识点(接上篇案例)
  • 动物排队+分手厨房?合作模拟《Pao Pao》登录steam
  • 易境通货代系统:如何实现全流程自动化报关管理?
  • OpenCV:答题卡识别
  • leetcode HOT100 个人理解及解析
  • 深入落地“人工智能+”,如何构建安全、高效的算力基础设施?
  • 无人出租车(Robotaxi)还有哪些技术瓶颈?
  • 安全开发生命周期管理
  • 用住宿楼模型彻底理解Kubernetes架构(运行原理视角)
  • 【大模型】minimind2 1: ubuntu24.04安装部署 web demo
  • 扩散模型之(八)Rectified Flow
  • Facebook主页变现功能被封?跨境玩家该如何申诉和预防