Echarts在Vue中的使用
2024-09-06 12:45:26
1、使用 cnpm 或 npm 安装 Echarts
cnpm方式
cnpm install echarts -S
或者 npm方式
npm install echarts --save
2、在项目文件的入口js文件main.js中添加
import echarts from "echarts"
3、在需要添加图表的组件中创建依赖的实例
var echarts = require('echarts');
使用这种方式得到的是已经加载了所有图表和组件的 ECharts 包,因此体积会比较大。也可以只按需引入需要的模块。例如
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入柱状图
require('echarts/lib/chart/bar');
// 引入提示框和标题组件
require('echarts/lib/component/tooltip');
require('echarts/lib/component/title');
4、在模板中创建图表容器(必须给出确定的宽高值(px),不能使用%)
<div class="charts">
<div class="headTable" :style="{width:'1200px',height:'30rem',background:'red'}" ref="headTable">
</div>
5、写入js
<script>
var echarts = require('echarts');
export default {
name:'charts',
data () {
return { }
},
methods: { },
mounted () {
/*ECharts图表*/
var myChart = echarts.init(this.$refs.headTable);
myChart.setOption({
series : [
{
name: '访问来源',
type: 'pie',
radius: '55%',
itemStyle: {
normal: {
// 阴影的大小
shadowBlur: 200,
// 阴影水平方向上的偏移
shadowOffsetX: 0,
// 阴影垂直方向上的偏移
shadowOffsetY: 0,
// 阴影颜色
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
},
data:[
{value:400, name:'搜索引擎'},
{value:335, name:'直接访问'},
{value:310, name:'邮件营销'},
{value:274, name:'联盟广告'},
{value:235, name:'视频广告'}
]
}
]
})
}
}
</script>
最新文章
- Java代码注释XXX TODO FIXME 的意义
- Spring框架学习[IoC容器高级特性]
- 内容在某div中滚动
- socat : Some useful commands
- C++拾遗(五)语句相关
- jquery实现div垂直居中
- 男装电子零售商East Dane即将面世_衣装_YOKA时尚网
- mysql 参数optimizer_switch
- NYOJ-1036 非洲小孩(贪心)
- js五种设计模式
- Simulation of empirical Bayesian methods (using baseball statistics)
- win8使用putty登录虚拟机linux
- mysql分组查询前n条数据
- PAT乙级考前总结(一)
- 异步async、await和Future的使用技巧
- Vue.js 开发环境的搭建
- Spring Cloud(Dalston.SR5)--Eureka 服务实例健康检查
- 报错程序包org.springframework.test.context不存在
- 模块讲解----configparser模块(my.cnf配置文件操作)
- 【转】梯度下降算法以及其Python实现
热门文章
- 二分图最佳匹配KM算法 /// 牛客暑期第五场E
- 【学术篇】luogu2184贪婪大陆
- NuGet 命令行使用EntityFrameWork
- leetcode-122-买卖股票的最佳时机②
- [JZOJ3293] 【SHTSC2013】阶乘字符串
- [JZOJ4649] 【NOIP2016提高A组模拟7.17】项链
- Win10弹出需要管理员权限才能删除文件夹,解决办法
- webpack静态资源拷贝插件
- Codeforces Round #599 (Div. 2)的简单题题解
- Mac OS下使用ll等命令