使用步驟
- 在專案下使用命令列,初始化工程的 npm 環境并安裝 echarts(這里前提是您已經安裝了 npm):
npm init
npm install echarts --save
2.匯入模塊到main.js(如果你只有一個組件都用echarts,那么就匯入區域)
全域
main.js:
import Vue from 'vue'
import echarts from 'echarts'
//需要掛載到Vue原型上
Vue.prototype.$echarts = echarts
之后的組件內部使用:
<template>
<div style="width: auto;height: 400px" id="main">
</div>
</template>
<script>
//通過this.$echarts來使用
export default {
name: "page",
mounted(){
// 在通過mounted呼叫即可
this.echartsInit()
},
methods: {
//初始化echarts
echartsInit() {
//柱形圖
//因為初始化echarts 的時候,需要指定的容器 id='main'
this.$echarts.init(document.getElementById('main')).setOption({
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [{
data: [120, 200, 150, 80, 70, 110, 130],
type: 'bar',
showBackground: true,
backgroundStyle: {
color: 'rgba(220, 220, 220, 0.8)'
}
}]
})
}
}
}
</script>
之后運行即可
區域
區域使用:
<template>
<div style="width: auto;height: 400px" id="main">
</div>
</template>
<script>
import echarts from 'echarts'
export default {
name: "echarts",
data() {
return {}
},
mounted() {
this.echartsInit()
},
methods:{
echartsInit() {
echarts.init(document.getElementById('main')).setOption({
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [{
data: [120, 200, 150, 80, 70, 110, 130],
type: 'bar',
showBackground: true,
backgroundStyle: {
color: 'rgba(220, 220, 220, 0.8)'
}
}]
})
}
}
}
</script>
<style scoped>
</style>
echarts官網教程:
https://echarts.apache.org/zh/tutorial.html#%E5%9C%A8%20webpack%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20ECharts
echarts官網還有更多的實體:
https://echarts.apache.org/examples/zh/index.html#chart-type-bar
1.進入官網
2.找到你想要的效果
3.點擊進入

4.復制代碼粘貼

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/214550.html
標籤:python
上一篇:c語言指標與結構體
