Vue?Echarts實現(xiàn)帶滾動效果的柱形圖
更新時間:2022年04月02日 18:08:35 作者:今天代碼敲了嗎
這篇文章主要為大家詳細(xì)介紹了Vue?Echarts實現(xiàn)帶滾動效果的柱形圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Vue Echarts實現(xiàn)帶滾動效果柱形圖的具體代碼,供大家參考,具體內(nèi)容如下
代碼
<template> ? <div class="timeLineview"> ? ? <div v-bind:style="{ height: heightData + 'px' }" ref="categoryChart"></div> ? ? <div v-bind:style="{ height: noHeight + 'px' }" class="nomore"> ? ? ? {{ noData }} ? ? </div> ? </div> </template> <script> import echarts from "echarts"; export default { ? components: {}, ? name: "timeLine", ? props: { ? ? question: {} ? }, ? data() { ? ? return { ? ? ? datainfo: [], ? ? ? datatitle: [], ? ? ? chart: null, ? ? ? heightData: 300, ? ? ? noHeight: 0, ? ? ? noData: "" ? ? }; ? }, ? methods: { ? ? resize() { ? ? ? this.chart.resize(); ? ? }, ? ? find() { ? ? //獲取數(shù)據(jù) ? ? ? if (this.question) { ? ? ? ? for (let index = 0; index < this.question.length; index++) { ? ? ? ? ? if (this.question[index].statValue > 0) { ? ? ? ? ? //y軸 ? ? ? ? ? ? this.datainfo.push(this.question[index].statValue); ? ? ? ? ? ? //X軸 ? ? ? ? ? ? this.datatitle.push(this.question[index].statLabel); ? ? ? ? ? } ? ? ? ? } ? ? ? } ? ? ? this.chart = echarts.init(this.$refs.categoryChart); ? ? ? const option = { ? ? ? ? tooltip: { ? ? ? ? ? trigger: "axis", ? ? ? ? ? axisPointer: { ? ? ? ? ? ? type: "shadow" ? ? ? ? ? } ? ? ? ? }, ? ? ? ? title: {}, ? ? ? ? legend: {}, ? ? ? ? dataZoom: [ ? ? ? ? ? { ? ? ? ? ? ? type: "slider", ? ? ? ? ? ? start: 0, ? ? ? ? ? ? end: (100 / this.datainfo.length) * 5 ? //顯示五個 ? ? ? ? ? }, ? ? ? ? ? { ? ? ? ? ? ? type: "inside", ? ? ? ? ? ? start: 0, ? ? ? ? ? ? end: (100 / this.datainfo.length) * 5//顯示五個 ? ? ? ? ? } ? ? ? ? ], ? ? ? ? xAxis: { ? ? ? ? ? data: this.datatitle ? ? ? ? }, ? ? ? ? yAxis: { minInterval: 1 }, ? //顯示為整數(shù) 最小間距1 ? ? ? ? series: [ ? ? ? ? ? { ? ? ? ? ? ? type: "bar", ? ? ? ? ? ? name: "數(shù)量", ? ? ? ? ? ? data: this.datainfo, ? ? ? ? ? ? itemStyle: { ? ? ? ? ? ? ? color: "#77bef7" ? ? ? ? ? ? } ? ? ? ? ? } ? ? ? ? ] ? ? ? }; ? ? ? this.chart.setOption(option); ? ? ? if (this.datainfo.length > 0) { ? ? ? ? this.heightData = 300; ? ? ? } else { ? ? ? ? this.heightData = 0; ? ? ? ? this.noHeight = 300; ? ? ? ? this.noData = "暫無數(shù)據(jù)"; ? ? ? } ? ? } ? }, ? mounted() { ? ? this.find(); ? }, ? created() {} }; </script> <style ?lang="less" scoped> .nomore { ? display: flex; ? justify-content: center; ? align-items: center; ? font-size: 18px; } </style>
效果圖
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Element?plus中el-input框回車觸發(fā)頁面刷新問題以及解決辦法
在el-form表單組件中el-input組件輸入內(nèi)容后按下Enter鍵刷新了整個頁面,下面這篇文章主要給大家介紹了關(guān)于Element?plus中el-input框回車觸發(fā)頁面刷新問題以及解決辦法,需要的朋友可以參考下2024-03-03