首页 / VUE / vue Echarts帧动画
vue Echarts帧动画
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了vue Echarts帧动画,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4344字,纯文字阅读大概需要7分钟。
内容图文
vue Echarts帧动画
1.效果如下:
2.源码如下:
1 <template> 2 <div class="chart"></div> 3 </template> 4 <script> 5 import Bus from "@/utils/bus.js"; 6 import { debounce } from "@/utils"; 7 8 export default { 9 name: "echarts2", 10 data() { 11 let initdata = 30 + Math.random().toFixed(4) * 4; 12 let barbaldata = []; 13 let ylinedata = []; 14 let xdata = []; 15for (var i = 0; i < 50; i++) { 16 barbaldata.push(0); 17 ylinedata.push(initdata); 18 xdata.push(i); 19 } 20 barbaldata.splice( 21 barbaldata.length - 1, 22 1, 23 ylinedata[ylinedata.length - 1] 24 ); 25return { 26 autoResize: { 27 type: Boolean, 28default: true 29 }, 30 chart: null, 31 sidebarElm: null, 32 chartData: { barbaldata, ylinedata, xdata } 33 }; 34 }, 35 36 watch: { 37 chartData: { 38 deep: true, 39//immediate:true, 40 handler(val) { 41this.drawEcharts(); 42 } 43 } 44 }, 45 mounted() { 46 Bus.$on("ToEcharts", e => { 47this.chartData.xdata.shift(); 48this.chartData.ylinedata.shift(); 49this.chartData.xdata.push(e); 50this.chartData.ylinedata.push(e); 51this.chartData.barbaldata.splice( 52this.chartData.barbaldata.length - 1, 53 1, 54 e 55 ); 56 }); 57 58this.resetSizefun(); 59 }, 60 beforeDestroy() { 61if (!this.chart) { 62return; 63 } 64if (this.autoResize) { 65 window.removeEventListener("resize", this.__resizeHandler); 66 } 67 68this.sidebarElm && 69this.sidebarElm.removeEventListener( 70 "transitionend", 71this.sidebarResizeHandler 72 ); 73 74this.chart.dispose(); 75this.chart = null; 76 }, 77 methods: { 78 drawEcharts() { 79this.$nextTick(() => { 80this.initChart(); 81 }); 82 }, 83 initChart() { 84this.chart = this.$echarts.init(this.$el, "macarons"); 85this.chart.clear(); 86this.setOptions(this.chartData); 87 }, 88 89 setOptions(chartData) { 90this.chart.setOption({ 91 backgroundColor: "#242424", 92 grid: { 93 top: "60", 94 bottom: "20", 95 right: "60", 96 left: "60" 97 }, 98 animation: false, 99 tooltip: { 100 trigger: "axis", 101 show: false, 102 axisPointer: { 103 type: "cross" 104 } 105 }, 106107 xAxis: { 108 type: "category", 109 boundaryGap: false, 110 splitLine: { show: false }, 111 axisLine: { 112 show: false113 }, 114 axisLabel: { 115 show: false116 }, 117 axisTick: { 118 show: false119 }, 120 data: chartData.xdata 121 }, 122 yAxis: { 123 type: "value", 124125 axisLabel: { 126 show: false, 127 formatter: "{value} " 128 }, 129 axisPointer: { 130 snap: true131 }, 132 splitLine: { show: false }, 133 axisLine: { 134 show: false135 }, 136 axisTick: { 137 show: false138 }, 139 connectNulls: true140 }, 141 series: [ 142 { 143 data: chartData.ylinedata, 144 type: "line", 145 animation: false, 146 smooth: true, 147 symbol: "none", 148 lineStyle: { 149 width: 2, 150 color: { 151 type: "linear", 152 colorStops: [ 153 { 154 offset: 0, 155 color: "#D575C2", // 0% 处的颜色,156 transition: 2 157 }, 158 { 159 offset: 0.66, 160 color: "#D575C2", // 66% 处的颜色161 transition: 2 162 }, 163 { 164 offset: 1, 165 color: "#fff", // 100% 处的颜色166 transition: 2 167 } 168 ], 169 opacity: 0.4, 170 globalCoord: false// 缺省为 false171 } 172 }, 173 width: 4 174 }, 175176 { 177 type: "bar", 178 data: chartData.barbaldata, 179 itemStyle: { 180 normal: { 181 color:"#D575C2", 182 opacity: 0.8, 183 } 184 }, 185 barWidth: 2, 186 animation: false, 187 markPoint: { 188 animation: false, 189 symbol: "circle", 190 data: [{ type: "max" }], 191 symbolSize: 10, 192 itemStyle: { 193 normal: { 194 color: "#fff", 195 borderColor: "#D575C2", 196 borderWidth: "2", 197 label: { 198 show: false199 } 200 } 201 } 202 } 203 } 204 ] 205 }); 206 }, 207 sidebarResizeHandler(e) { 208if (e.propertyName === "width") { 209this.__resizeHandler(); 210 } 211 }, 212//窗口改变执行方法213 resetSizefun() { 214if (this.autoResize) { 215this.__resizeHandler = debounce(() => { 216if (this.chart) { 217this.chart.resize(); 218 } 219 }, 100); 220 window.addEventListener("resize", this.__resizeHandler); 221 } 222223// 监听侧边栏的变化224this.sidebarElm = document.getElementsByClassName("sidebar-container")[0]; 225this.sidebarElm && 226this.sidebarElm.addEventListener( 227 "transitionend", 228this.sidebarResizeHandler 229 ); 230 } 231 } 232}; 233 </script> 234 <style lang="scss" scoped> 235.chart { 236 width: 100%; 237 height: 428px; 238} 239 </style>
原文:https://www.cnblogs.com/volodya/p/14231285.html
内容总结
以上是互联网集市为您收集整理的vue Echarts帧动画全部内容,希望文章能够帮你解决vue Echarts帧动画所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。