vue项目开发中经常会用到百度echarts
,那么我们需要安装哪些脚手架呢?下面编程教程网小编给大家简单介绍一下!
安装脚手架
npm install echarts --save
全局引入
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
创建图表
<template>
<div>
<div class="charts">
<div id="bar" style="height: 350px;"></div>
</div>
</div>
</template>
<script>
// 引入基本模板,按需加载
let echarts = require('echarts/lib/echarts');
// 引入柱状图
require('echarts/lib/chart/bar');
require('echarts/lib/component/tooltip');
require('echarts/lib/component/title');
export default {
mounted(){
this.drawBar();
},
methods:{
drawBar(){
let bar = echarts.init(document.getElementById('bar'));
// 绘制图表
bar.setOption({
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c}'
},
legend: {
left: 'center',
data: ['本年', '上年'],
bottom:0
},
xAxis: {
type: 'category',
name: 'x',
splitLine: {show: false},
data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
},
grid: {
left: '1%',
right: '2%',
bottom: '8%',
containLabel: true
},
yAxis: {
type: 'category',
name: 'y',
splitLine: {show: true},
data:['10%','20%','30%','40%','50%','60%','70%','80%','90%','100%']
},
series: [
{
name: '本年',
type: 'line',
data: [0.8, 0.98, 0.96, 0.27, 0.81, 0.47, 0.74, 0.23, .69, 0.25, 0.36, 0.56]
},
{
name: '上年',
type: 'line',
data: [1, 0.2, 0.4, 0.8, 0.16, 0.32, 0.64, 1.28, 5.6, 0.25, 0.63, 0.65, 0.12]
},
]
})
},
}
}
</script>
以上是编程学习网小编为您介绍的“vue项目如何结合百度echarts生成图表”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。
沃梦达教程
本文标题为:vue项目如何结合百度echarts生成图表


猜你喜欢
- CSS3中Transition动画属性用法详解 2024-01-03
- 理论普及——用户体验 2024-01-04
- 从富文本编辑器获取html内容组装json,特殊字符引起报错解决办法。 2023-10-27
- 创建与框架无关的JavaScript插件 2023-11-30
- Js实现滚动变色的文字效果 2023-12-25
- pyqt5 设置窗体透明控件不透明的操作 2024-02-25
- Vue3.0 性能提升主要是通过哪几方面体现的? 2023-10-08
- JS控制弹出悬浮窗口(一览画面)的实例代码 2024-02-07
- 微信小程序 wx:for遍历循环使用实例解析 2024-01-14
- Vue如何实现低版本浏览器兼容问题(兼容IE8浏览器) 2025-01-14