vue下使用Echarts5绘制基础图表

编程入门 行业动态 更新时间:2024-10-24 15:17:52

vue下使用Echarts5绘制基础<a href=https://www.elefans.com/category/jswz/34/1770092.html style=图表"/>

vue下使用Echarts5绘制基础图表

项目使用Vue3加Echarts5绘制的基本图表,图表自适应浏览器窗口大小 先上图,大屏小屏都可完美展示,纯属练手

一 先上图

1.任意缩放窗口的大小
2.平板

3.电脑

4.饼图

5.折线图

二 后上代码

<script lang="ts">
import {defineComponent,watch,getCurrentInstance,onMounted} from 'vue'
import * as echarts from 'echarts';
import { useUserStore } from  '@/store/app.ts'export default defineComponent({name: "index",setup() {const user = useUserStore()const { $echarts } = getCurrentInstance().appContext.config.globalPropertieswatch(()=>user.isCollapse,(newV,oldV)=>{console.log(oldV,newV,"111")setTimeout(()=>{myChart.resize()},300)})onMounted(() => {const  myChart = echarts.init(document.getElementById('charts'))const  clockCharts = echarts.init(document.getElementById('clockCharts'))const  radar = echarts.init(document.getElementById('radar'))const  scatter = echarts.init(document.getElementById('scatter'))window.addEventListener('resize', () => {myChart.resize()clockCharts.resize()radar.resize()scatter.resize()})scatter.setOption({xAxis: {},yAxis: {},series: [{symbolSize: 20,data: [[10.0, 8.04],[8.07, 6.95],[13.0, 7.58],[9.05, 8.81],[11.0, 8.33],[14.0, 7.66],[13.4, 6.81],[10.0, 6.33],[14.0, 8.96],[12.5, 6.82],[9.15, 7.2],[11.5, 7.2],[3.03, 4.23],[12.2, 7.83],[2.02, 4.47],[1.05, 3.33],[4.05, 4.96],[6.03, 7.24],[12.0, 6.26],[12.0, 8.84],[7.08, 5.82],[5.02, 5.68]],type: 'scatter'}]})radar.setOption( {title: {text: 'Proportion of Browsers',subtext: 'Fake Data',top: 10,left: 10},tooltip: {trigger: 'item'},legend: {type: 'scroll',bottom: 10,data: (function () {var list = [];for (var i = 1; i <= 28; i++) {list.push(i + 2000 + '');}return list;})()},visualMap: {top: 'middle',right: 10,color: ['red', 'yellow'],calculable: true},radar: {indicator: [{ text: 'IE8-', max: 400 },{ text: 'IE9+', max: 400 },{ text: 'Safari', max: 400 },{ text: 'Firefox', max: 400 },{ text: 'Chrome', max: 400 }]},series: (function () {var series = [];for (var i = 1; i <= 28; i++) {series.push({type: 'radar',symbol: 'none',lineStyle: {width: 1},emphasis: {areaStyle: {color: 'rgba(0,250,0,0.3)'}},data: [{value: [(40 - i) * 10,(38 - i) * 4 + 60,i * 5 + 10,i * 9,(i * i) / 2],name: i + 2000 + ''}]});}return series;})()})clockCharts.setOption({tooltip: {formatter: '{a} <br/>{b} : {c}%'},series: [{name: 'Pressure',type: 'gauge',detail: {formatter: '{value}'},data: [{value: 60,name: '分数'}]}]})// 绘制图表myChart.setOption({title: {text: 'ECharts 入门示例'},tooltip: {},xAxis: {data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']},yAxis: {},series: [{name: '销量',type: 'bar',data: [5, 20, 36, 10, 10, 20]}]})})return {}},})
</script><template><div style="display: flex"><div id="charts" style="width: 50%; height: 400px ;flex: 1"></div><div id="clockCharts" style="width: 50%; height: 400px;flex: 1"></div></div><div style="display: flex"><div id="radar" style="width: 50%; height: 400px ;flex: 1"></div><div id="scatter" style="width: 50%; height: 400px;flex: 1"></div></div>
</template><style scoped lang="less"></style>

更多推荐

vue下使用Echarts5绘制基础图表

本文发布于:2023-11-15 23:15:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图表   基础   vue

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!