這篇文章主要介紹vue.js引入echars的方法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
成都創(chuàng)新互聯(lián)2013年開(kāi)創(chuàng)至今,先為婁煩等服務(wù)建站,婁煩等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為婁煩企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
vue.js引入echars的方法:1、全局引入,代碼為【title:{text: 'ECharts 入門示例'}】;2、按需引入,代碼為【require('echarts/lib/component/tooltip')】。
vue.js引入echars的方法:
1.安裝echarts依賴
npm install echarts -S
2.創(chuàng)建圖表
a:全局引入
main.js頁(yè)面 import echarts from 'echarts' Vue.prototype.$echarts = echarts Hello.vue頁(yè)面 <div id="myChart" :style="{width: '300px', height: '300px'}"></div> <script> export default { name: 'FuncFormsBase', data () { return { msg: 'Welcome to Your Vue.js App' } }, mounted () { this.drawLine(); }, methods: { drawLine () { var echarts = require('echarts'); var myChart = echarts.init(document.getElementById('main')); myChart.setOption({ title: { text: 'ECharts 入門示例' }, tooltip: {}, xAxis: { data: ['襯衫', '羊毛衫', '雪紡衫', '褲子', '高跟鞋', '襪子'] }, yAxis: {}, series: [{ name: '銷量', type: 'bar', data: [5, 20, 36, 10, 10, 20] }] }); } } } </script> <style scoped> </style>
b:按需引入
上面全局引入會(huì)將所有的echarts圖表打包,導(dǎo)致體積過(guò)大,所以我覺(jué)得最好還是按需引入。
// 引入基本模板 let echarts = require('echarts/lib/echarts') // 引入柱狀圖組件 require('echarts/lib/chart/bar') // 引入提示框和title組件 require('echarts/lib/component/tooltip') require('echarts/lib/component/title') export default { name: 'hello', data() { return { msg: 'Welcome to Your Vue.js App' } }, mounted() { this.drawLine(); }, methods: { drawLine() { // 基于準(zhǔn)備好的dom,初始化echarts實(shí)例 let myChart = echarts.init(document.getElementById('myChart')) // 繪制圖表 myChart.setOption({ title: { text: 'ECharts 入門示例' }, tooltip: {}, xAxis: { data: ["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"] }, yAxis: {}, series: [{ name: '銷量', type: 'bar', data: [5, 20, 36, 10, 10, 20] }] }); } } }
以上是“vue.js引入echars的方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
本文題目:vue.js引入echars的方法
文章源于:http://www.rwnh.cn/article32/ipcesc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)站設(shè)計(jì)公司、ChatGPT、定制網(wǎng)站、網(wǎng)站制作、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)