vue中通過tabs 切換 時 顯示不同的echarts 特殊處理

需要進行特殊處理?

比如強制 進行resize 的方法 不然 大小顯示會出現問題

我先把全部的代碼弄上

<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount, nextTick } from 'vue'
import { useRoute } from 'vue-router'
import { message } from 'ant-design-vue'
import { useBrandStore } from '@/store/modules/brand'
import { Chart } from '@antv/g2'
import * as  echarts from 'echarts'
import { InfoCircleOutlined, CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons-vue'const brandStore = useBrandStore()
const route = useRoute()
const chart1 = ref(null)
const chart2 = ref(null)
const chartInstances = ref<{chart1: echarts.ECharts | nullchart2: echarts.ECharts | null
}>({chart1: null,chart2: null
})// 初始化圖表實例
const initChartInstance = (container: HTMLElement | null) => {if (!container) return nullreturn echarts.init(container)
}// 初始化所有圖表
const initAllCharts = () => {chartInstances.value.chart1 = initChartInstance(chart1.value)chartInstances.value.chart2 = initChartInstance(chart2.value)// 設置初始選項if (chartInstances.value.chart1) {initChart1()}if (chartInstances.value.chart2) {initChart2()}// 添加resize事件監聽const resizeHandler = () => {Object.values(chartInstances.value).forEach(chart => {chart?.resize()})}window.addEventListener('resize', resizeHandler)// 組件卸載時清理onBeforeUnmount(() => {window.removeEventListener('resize', resizeHandler)Object.values(chartInstances.value).forEach(chart => {chart?.dispose()})})
}const initChart = () => {var myChart = echarts.init(document.getElementById('chartContainer'));var option = {tooltip: {trigger: 'axis', // 觸發類型,'axis' 表示在坐標軸上觸發formatter: function (params) {// 自定義提示框內容var result = params[0].axisValue + '<br/>';result += '曝光數: ' + params[0].data;return result;}},grid: {top: 5,right: 5,bottom: 5,left: 5},xAxis: {type: 'category',// data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],show: false},yAxis: {type: 'value',show: false},series: [{data: [264, 417, 438, 887, 309, 397, 550, 575, 563, 430, 525, 592, 492, 467, 513,546, 983, 340, 539, 243, 226, 192,],type: 'line',smooth: true,areaStyle: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: 'rgba(128, 109, 224, 0.3)'}, {offset: 1,color: 'rgba(128, 109, 224, 0)'}])},lineStyle: {color: '#806de0'},symbol: 'none'}]};myChart.setOption(option);window.addEventListener('resize', function () {myChart.resize();});}const tabs = ref(["詢單轉換分析圖", "熱度數據分析圖"])
const activeTab = ref(0)
onMounted(() => {initChart()initAllCharts()})
const handleChangeTabs = async(index: any) => {activeTab.value = index// 等待DOM更新完成await nextTick()// 強制觸發所有圖表的resizeObject.values(chartInstances.value).forEach(chart => {chart?.resize()})if (index == 0) {initChart1()}if (index == 1) {initChart2()}
}const initChart1 = () => {var myChart = echarts.init(chart1.value);// 指定圖表的配置項和數據var option = {title: {// text: '詢單轉化分析圖',// subtext: '熱度數據分析圖'},tooltip: {trigger: 'axis',axisPointer: {type: 'shadow'}},legend: {data: ['詢單次', '支付單數'],},grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},xAxis: {type: 'category',data: ['2025-05-29', '2025-05-30', '2025-05-31', '2025-06-01', '2025-06-02', '2025-06-03', '2025-06-04']},yAxis: {type: 'value'},series: [{name: '詢單次',type: 'bar',barWidth: '40%', // 調整柱子的寬度itemStyle: {color: '#1E90FF' // 藍色},data: [50, 300, 600, 580, 480, 280, 100]},{name: '支付單數',type: 'bar',barWidth: '40%',itemStyle: {color: '#00CED1' // 綠色},data: [200, 400, 450, 300, 200, 100, 20]}]};// 使用配置項顯示圖表myChart.setOption(option);window.addEventListener('resize', function () {myChart.resize();});}
const initChart2 = () => {const myChart = echarts.init(chart2.value);const option = {title: {// text: '數據趨勢分析',// subtext: '想要數、瀏覽數、曝光數變化趨勢',left: 'center'},tooltip: {trigger: 'axis',axisPointer: {type: 'cross',label: {backgroundColor: '#6a7985'}}},legend: {data: ['想要數', '瀏覽數', '曝光數'],top: 30},grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},xAxis: {type: 'category',boundaryGap: false,data: ['2025-05-28', '2025-05-29', '2025-05-30', '2025-05-31', '2025-06-01', '2025-06-02', '2025-06-03']},yAxis: {type: 'value'},series: [{name: '曝光數',type: 'line',stack: '總量',areaStyle: {},emphasis: {focus: 'series'},data: [10, 20, 200, 180, 10, 5, 2],itemStyle: {color: '#73DDD7' // 淺青色},lineStyle: {width: 2},symbol: 'circle',symbolSize: 8},{name: '瀏覽數',type: 'line',stack: '總量',areaStyle: {},emphasis: {focus: 'series'},data: [5, 15, 160, 150, 8, 3, 1],itemStyle: {color: '#FFD591' // 淺橙色},lineStyle: {width: 2},symbol: 'circle',symbolSize: 8},{name: '想要數',type: 'line',stack: '總量',areaStyle: {},emphasis: {focus: 'series'},data: [2, 10, 80, 70, 5, 2, 0.5],itemStyle: {color: '#A6C8FF' // 淺藍色},lineStyle: {width: 2},symbol: 'circle',symbolSize: 8}]};myChart.setOption(option);// 響應式調整window.addEventListener('resize', function () {myChart.resize();});
}const storeList = ref([{id: 1,name: "xxxxxxxxxx",number: 323214},{id: 2,name: "xxxxxxxxxx",number: 323214},{id: 3,name: "xxxxxxxxxx",number: 323214},{id: 4,name: "xxxxxxxxxx",number: 323214},{id: 5,name: "xxxxxxxxxx",number: 323214},{id: 6,name: "xxxxxxxxxx",number: 323214},{id: 7,name: "xxxxxxxxxx",number: 323214},{id: 8,name: "xxxxxxxxxx",number: 323214},{id: 9,name: "xxxxxxxxxx",number: 323214},{id: 10,name: "xxxxxxxxxx",number: 323214},{id: 1,name: "xxxxxxxxxx",number: 323214},{id: 2,name: "xxxxxxxxxx",number: 323214},{id: 3,name: "xxxxxxxxxx",number: 323214},{id: 4,name: "xxxxxxxxxx",number: 323214},{id: 5,name: "xxxxxxxxxx",number: 323214},{id: 6,name: "xxxxxxxxxx",number: 323214},{id: 7,name: "xxxxxxxxxx",number: 323214},{id: 8,name: "xxxxxxxxxx",number: 323214},{id: 9,name: "xxxxxxxxxx",number: 323214},{id: 10,name: "xxxxxxxxxx",number: 323214}
])</script>
<template><page-container :title="route.meta.title"><!-- <a-card>待開發...</a-card> --><a-row :gutter="[16, 24]"><a-col class="gutter-row" :xl="6" :lg="12" :md="12" :sm="24" :xs="24"><a-card><div class="col-data-item"><div class="col-data-item__title"><div>影票代訂-詢單次數-今日實時</div><InfoCircleOutlined /></div><div class="col-data-item__number">163次</div><div class="col-data-item__compare"><div class="compare_1"><div class="compare_1__title">周同比</div><div class="compare_1__number"><span>12%</span><span><CaretUpOutlined style="color: red" /></span></div></div><div class="compare_2"><div class="compare_1__title">日同比</div><div class="compare_1__number"><span>12%</span><span><CaretDownOutlined style="color: green" /></span></div></div></div><div class="col-data-item__line"><a-divider style="height: 1px; background-color: #f7f8f9; padding: 0" /></div><div class="col-data-item__footer"><div><span>支付單數 35單</span><span>轉換率 (21.4%)</span></div></div></div></a-card></a-col><a-col class="gutter-row" :xl="6" :lg="12" :md="12" :sm="24" :xs="24"><a-card><div class="col-data-item"><div class="col-data-item__title"><div>影票代訂-訂單提交-今日實時</div><InfoCircleOutlined /></div><div class="col-data-item__number">163次</div><div class="col-data-item__compare"><div class="compare_1"><div class="compare_1__title">周同比</div><div class="compare_1__number"><span>12%</span><span><CaretUpOutlined style="color: red" /></span></div></div><div class="compare_2"><div class="compare_1__title">日同比</div><div class="compare_1__number"><span>12%</span><span><CaretDownOutlined style="color: green" /></span></div></div></div><div class="col-data-item__line"><a-divider style="height: 1px; background-color: #f7f8f9; padding: 0" /></div><div class="col-data-item__footer"><div><span>支付單數 35單</span><span>轉換率 (21.4%)</span></div></div></div></a-card></a-col><a-col class="gutter-row" :xl="6" :lg="12" :md="12" :sm="24" :xs="24"><a-card><div class="col-data-item"><div class="col-data-item__title"><div>影票代訂-訂單利潤-今日實時</div><InfoCircleOutlined /></div><div class="col-data-item__number">163次</div><div class="col-data-item__compare"><div class="compare_1"><div class="compare_1__title">周同比</div><div class="compare_1__number"><span>12%</span><span><CaretUpOutlined style="color: red" /></span></div></div><div class="compare_2"><div class="compare_1__title">日同比</div><div class="compare_1__number"><span>12%</span><span><CaretDownOutlined style="color: green" /></span></div></div></div><div class="col-data-item__line"><a-divider style="height: 1px; background-color: #f7f8f9; padding: 0" /></div><div class="col-data-item__footer"><div><span>支付單數 35單</span><span>轉換率 (21.4%)</span></div></div></div></a-card></a-col><a-col class="gutter-row" :xl="6" :lg="12" :md="12" :sm="24" :xs="24"><a-card><div class="col-data-item"><div class="col-data-item__title"><div>今日曝光新增</div><InfoCircleOutlined /></div><div class="col-data-item__number">8,846</div><div class="col-data-item__compare"><div id="chartContainer" style="width: 100%; height: 80px"></div></div><div class="col-data-item__line"><a-divider style="height: 1px; background-color: #f7f8f9; padding: 0" /></div></div></a-card></a-col></a-row><div class="echart-content-container"><div class="row1"><div class="left-tabs"><div class="item" v-for="(item, index) in tabs" @click="handleChangeTabs(index)":class="{ active: index === activeTab }" :key="index">{{ item }}</div></div></div><a-row :gutter="24"><a-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24"><div class="left-chart1" v-show="activeTab == 0"><div ref="chart1" style="width: 100%; height: 100%;"></div></div><div class="left-chart1" v-show="activeTab == 1"><div ref="chart2" style="width: 100%; height: 100%;"></div></div></a-col><a-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24"><div class="right-chart1"><div class="list-product"><div class="item" v-for="(item, index) in storeList" :key="index"><div class="left"><div class="number">{{ item.id }}</div><div class="name">{{ item.name }}</div></div><div class="right">{{ item.number }}</div></div></div></div></a-col></a-row></div><!-- <a-row :gutter="[16, 24]"></a-row> --></page-container>
</template><style lang="less" scoped>
.echart-content-container {padding: 20px;border-radius: 5px;margin-top: 20px;background-color: #fff;.row1 {padding: 10px 0;border-bottom: 1px solid #eee;.left-tabs {display: flex;align-items: center;.item {font-size: 14px;color: #000;cursor: pointer;transition: all 0.6s;}.item:nth-child(n+2) {margin-left: 20px;}.active {color: #1890ff;position: relative;&::after {content: "";height: 2px;width: 100%;position: absolute;top: 30px;left: 0;background-color: #1890ff;transition: all 0.6s;/* 可選:為下劃線添加過渡效果 */}}}}.left-chart1 {width: 100%;height: 400px; // 固定高度確保圖表顯示min-height: 400px; // 防止內容壓縮#chart1 {width: 100%;height: 100%;}#chart2 {width: 100%;height: 100%;}}.right-chart1 {width: 100%;height: 400px; // 與左側保持一致padding-left: 20px; // 替代 margin-left 更安全.list-product {height: 100%;overflow-y: auto; // 明確指定垂直滾動padding: 10px;background: #fff;border-radius: 4px;box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);.item {display: flex;justify-content: space-between;align-items: center; // 垂直居中padding: 12px 0;border-bottom: 1px solid #f0f0f0;.left {display: flex;align-items: center;.number {font-weight: bold;color: #1890ff;min-width: 24px; // 防止數字跳動}.name {margin-left: 12px;color: #333;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 200px; // 防止過長文本}}.right {font-weight: bold;color: #52c41a;}}.item:last-child {border-bottom: none; // 移除最后一項的下邊框}}}// 響應式調整@media (max-width: 768px) {.left-chart1 {margin-top: 20px;padding-left: 0;height: auto;max-height: 300px;width: 100%;}}
}.col-data-item {height: 200px;.col-data-item__title {display: flex;align-items: center;justify-content: space-between;font-size: 16px;color: #858a99;}.col-data-item__number {font-size: 24px;font-weight: 700;margin-top: 5px;}.col-data-item__compare {display: flex;align-items: center;margin-top: 10px;.compare_1 {display: flex;align-items: center;.compare_1__title {}.compare_1__number {margin-left: 10px;}}.compare_2 {display: flex;align-items: center;margin-left: 30px;.compare_1__title {}.compare_1__number {margin-left: 10px;}}}
}.hiddenText {display: inline-block;width: 1000px;overflow: hidden;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;
}a:hover {color: red;
}.one {width: 100%;height: 400px;
}
</style>

這里的 chart1 和chart2 是這兩個echarts 圖

進行tabs 切換的時候 這兩個echarts 其實 是一開始是顯示好的

目前我是這樣處理的 在點擊tabs 的時候? 顯示echarts? 當前的echarts 的大小會有問題

目前我沒想到怎么處理

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/913705.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/913705.shtml
英文地址,請注明出處:http://en.pswp.cn/news/913705.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

淺度解讀-(未完成版)淺層神經網絡-深層神經網絡

文章目錄淺層神經網絡的前向傳播計算流程矩陣在運算時形狀的變化激活函數的作用為什么要有激活函數反向傳播深層神經網絡參數超參數參數初始化初始化權重的值選擇淺層神經網絡的前向傳播 計算流程 #mermaid-svg-tMPs4IUCtqxvhJ24 {font-family:"trebuchet ms",verda…

【vben3源碼解讀】【useEcharts】【VueUse】詳解useEcharts這個hooks的作用與相關庫的使用(VueUse)

源代碼 import type { EChartsOption } from echarts;import type { Ref } from vue;import type { Nullable } from vben/types;import type EchartsUI from ./echarts-ui.vue;import { computed, nextTick, watch } from vue;import { usePreferences } from vben/preference…

報錯 400 和405解決方案

今天出了好多這個錯誤&#xff0c;Uncaught (in promise) AxiosError {message: Request failed with status code 400 , name: AxiosError , code: ERR_BAD_REQUEST , config: {…}, request: XMLHttpRequest, …}反正就是前后端的參數不匹配&#xff0c;要不就是請求方式不…

Java源碼的前端編譯

Java源碼的前端編譯 歡迎來到我的博客&#xff1a;TWind的博客 我的CSDN:&#xff1a;Thanwind-CSDN博客 我的掘金&#xff1a;Thanwinde 的個人主頁 0.前言 當一份Java代碼寫好時&#xff0c;將其進行編譯&#xff0c;運行&#xff0c;并不是簡單把這個Java源碼從頭到尾執行…

JWT6報錯誤 kid empty unable to lookup correct key

JWT5和jwt6在加密和解密和時候還明些區別的 &#xff0c;在5中&#xff0c;是不需要這個kid的&#xff0c;加解都不需要。但6中是需要這個keyId。 所以在使用的時候要做個區別&#xff0c;參考下面鏈接&#xff1a; ThinkPhp5.0.24 JWT報錯 ‘“kid“ empty, unable to lookup…

高效學習之一篇搞定分布式管理系統Git !

一、Git是什么1&#xff0e;Git是目前世界上最先進的分布式版本管理系統 2&#xff0e;工作原理/流程workspace&#xff1a;工作區 Index/Stage&#xff1a;暫存區 Repository&#xff1a;倉庫區&#xff08;本地倉庫&#xff09; Remote&#xff1a;遠程倉庫二、SVN和Git的最主…

AdsPower API 新增查詢環境 Cookies 接口,自動化更進一步!

你是不是有過這樣的經歷&#xff1f;賬號在 AdsPower 環境中已經成功登錄&#xff0c;但你還要花時間手動導出 Cookies、再整理處理&#xff0c;過程繁瑣、效率低下。 現在&#xff0c;我們上線了 API 查詢環境 Cookies 的接口&#xff0c;支持通過 API 直接獲取已登錄環境的 …

Craftium游戲引擎中的客戶端同步機制解析

Craftium游戲引擎中的客戶端同步機制解析 craftium A framework for creating rich, 3D, Minecraft-like single and multi-agent environments for AI research based on Minetest 項目地址: https://gitcode.com/gh_mirrors/cr/craftium 游戲狀態同步的核心問題 在分…

spring cloud負載均衡之FeignBlockingLoadBalancerClient、BlockingLoadBalancerClient

本文主要分析被 FeignClient 注解的接口類請求過程中負載均衡邏輯&#xff0c;流程分析使用的源碼版本信息如下&#xff1a;<spring-boot.version>3.2.1</spring-boot.version><spring-cloud.version>2023.0.0</spring-cloud.version>背景 平常我們代碼…

提示工程(Prompt Engineering)研究進展

提示工程(Prompt Engineering)研究進展 以及它如何幫助大語言模型(LLMs)和視覺語言模型(VLMs)更好地工作。用簡單的話說,就是通過設計巧妙的“提示”(比如指令、例子),讓模型在不修改內部參數的情況下,更精準地完成各種任務,比如回答問題、推理、生成內容等。 文檔…

【ARM】AI開發板A7處理器JTAG實現指南

一、文檔背景盡管開發板原廠提供了相關文檔&#xff0c;但可能缺乏對 A7 處理器 JTAG 功能的詳細說明。這可能會導致以下問題&#xff1a;開發人員難以理解和利用 A7 處理器的基本功能&#xff0c;阻礙調試和開發進度。在進行Uboot移植過程中&#xff0c;無法應用圖形界面的調試…

FPGA(一)Quartus II 13.1及modelsim與modelsim-altera安裝教程及可能遇到的相關問題

零.前言 在學習FPGA課程時&#xff0c;感覺學校機房電腦用起來不是很方便&#xff0c;想著在自己電腦上下載一個Quartus II 來進行 基于 vhdl 語言的FPGA開發。原以為是一件很簡單的事情&#xff0c;沒想到搜了全網文章發現幾乎沒有一個完整且詳細的流程教學安裝&#xff08;也…

軟考(軟件設計師)存儲管理—存儲空間管理,文件共享保護

一、文件存取方法 1. 順序存取&#xff08;Sequential Access&#xff09; 原理&#xff1a;按記錄寫入順序依次訪問特點&#xff1a; 讀操作&#xff1a;讀取當前位置&#xff0c;指針自動前移寫操作&#xff1a;追加到文件末尾 適用場景&#xff1a;磁帶設備、日志文件 #merm…

Thinkphp6中如何將macro方法集成到Request類中

在學習crmeb的時候發現他使用了一個macro的方法用在中間件中&#xff0c;于對macro進行了簡單的研究&#xff0c;發現這個方法可以在中間件中進行定義一些方法&#xff0c;然后讓后面的控制器進行使用。 如&#xff1a; 在授權的中間件中&#xff0c;定義了$request->macro…

Java List 使用詳解:從入門到精通

一、List 基礎概念1.1 什么是 List&#xff1f;List 就像是一個智能書架&#xff1a;可以按順序存放書籍&#xff08;元素&#xff09;每本書都有固定位置&#xff08;索引&#xff09;可以隨時添加、取出或重新排列書籍// 創建一個書架&#xff08;List&#xff09; List<S…

Java零基礎筆記06(數組:一維數組、二維數組)

明確: 程序是用來處理數據的, 因此要掌握數據處理的數據結構數組是編程中常用的數據結構之一&#xff0c;用于存儲一系列相同類型的元素。在Java中&#xff0c;數組是一種對象&#xff0c;可以存儲固定大小的相同類型元素的集合。1.一維數組數組是一個數據容器,可用來存儲一批同…

10倍處理效率提升!阿里云大數據AI平臺發布智能駕駛數據預處理解決方案

阿里云大數據AI平臺重磅發布智能駕駛數據預處理解決方案&#xff0c;可幫助汽車行業客戶實現構建高效、穩定的數據預處理產線流程&#xff0c;數據包處理效率相比自建可提升10倍以上&#xff0c;數據處理推理任務優化提速1倍以上&#xff0c;相同資源產能提升1倍[1]&#xff0c…

SAP HANA內存數據庫解析:特性、優勢與應用場景 | 技術指南

SAP HANA 是一款列式內存關系數據庫&#xff0c;集 OLAP 和 OLTP 操作于一體。相較于同類產品&#xff0c;SAP HANA 需要的磁盤空間更少&#xff0c;并且可擴展性高。SAP HANA 可以部署在本地、公有云或私有云以及混合場景中。該數據庫適用于各種數據類型的高級分析和事務處理。…

Openharmony4.0 rk3566上面rknn的完美調用

一 背景&#xff1a; 我們都知道如果要在android上面使用rknn推理模型需要按照如下的步驟&#xff1a; 詳細請參考筆者的文章&#xff1a;Android11-rk3566平臺上采用NCNN&#xff0c;RKNN框架推理yolo11官方模型的具體步驟以及性能比較-CSDN博客 簡而言之就是 模型轉換&#…

Java多線程知識小結:Synchronized

在Java中&#xff0c;synchronized 關鍵字是實現線程同步的核心工具&#xff0c;用于保證同一時刻只有一個線程可以執行被修飾的代碼塊或方法。以下從基本原理、鎖升級過程、應用場景及優化建議四個維度詳細解析&#xff1a; 一、基本原理 1. 同步的對象 synchronized 鎖的是對…