前端笔记-vue cli使用echarts
生活随笔
收集整理的這篇文章主要介紹了
前端笔记-vue cli使用echarts
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
?
過程
代碼與實(shí)例
?
過程
首先下載echarts
?
下載好后:
在main.js中導(dǎo)入:
import echarts from 'echarts' Vue.prototype.$axios=Axios在vue中實(shí)例下:
<template><div><div><div id="main" style="width: 500px; height:500px"></div></div></div> </template>script如下:
<script> export default {mounted(){this.drawLine();},methods: {handleSubmit(){.........},//開始畫圖了drawLine(){// 基于準(zhǔn)備好的dom,初始化echarts實(shí)例//var myChart = this.$echarts.init(document.getElementById('main'));let myChart = this.$echarts.init(document.getElementById('main'));// 指定圖表的配置項(xiàng)和數(shù)據(jù)let option = {title: {text: 'ECharts 入門示例'},tooltip: {},legend: {data:['銷量']},xAxis: {data: ["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","襪子"]},yAxis: {},series: [{name: '銷量',type: 'bar',data: [5, 20, 36, 10, 10, 20]}]};// 使用剛指定的配置項(xiàng)和數(shù)據(jù)顯示圖表。myChart.setOption(option);}} } </script>程序運(yùn)行截圖如下:
?
?
代碼與實(shí)例
結(jié)構(gòu)如下:
源碼如下:
main.js
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' import Axios from 'axios' import echarts from 'echarts' import TestEChart from './TestEChart'Vue.config.productionTip = false Vue.prototype.$axios=Axios Vue.prototype.$echarts = echarts/* eslint-disable no-new */ new Vue({el: '#app',components: { TestEChart },template: '<TestEChart/>', })TestEChart.vue
<template><div><div><div id="main" style="width: 500px; height:500px"></div></div><div><button @click="handleSubmit">獲取</button></div></div> </template><script> export default {mounted(){this.drawLine();},methods: {handleSubmit(){this.$axios({type: 'get',url: '/gra/list'}).then(res => {console.log(res)}).catch(err=>{alert(err)})},//開始畫圖了drawLine(){// 基于準(zhǔn)備好的dom,初始化echarts實(shí)例//var myChart = this.$echarts.init(document.getElementById('main'));let myChart = this.$echarts.init(document.getElementById('main'));// 指定圖表的配置項(xiàng)和數(shù)據(jù)let option = {title: {text: 'ECharts 入門示例'},tooltip: {},legend: {data:['銷量']},xAxis: {data: ["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","襪子"]},yAxis: {},series: [{name: '銷量',type: 'bar',data: [5, 20, 36, 10, 10, 20]}]};// 使用剛指定的配置項(xiàng)和數(shù)據(jù)顯示圖表。myChart.setOption(option);}} } </script><style></style>?
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的前端笔记-vue cli使用echarts的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python笔记-解决开启Fiddler
- 下一篇: Flask笔记-任务框架搭建