vuejs中使用echarts
<style scoped>
.content {
/*自行添加样式即可*/
} #main {
/*需要制定具体高度,以px为单位*/
height: 400px;
}
</style>
<template>
<div class="content">
<div id="main"></div>
</div>
</template>
<script>
// 导入echarts
import echarts from 'echarts'
// 方便AJAX,按个人喜好添加,然后对应修改下方获取数据的代码
import $ from 'jquery'
// 皮肤引入 import theme-name from theme-folder // 以饼图为例
// 其他种类图表配置项参见百度echarts官网 export default {
data() {
return {
// 初始化空对象
chart: null,
// 初始化图表配置
opinion: ['高富帅', '矮富帅', '高富挫', '矮富挫', '女生'],
opinionData: [{
value: 26,
name: '高富帅'
}, {
value: 31,
name: '矮富帅'
}, {
value: 18,
name: '高富挫'
}, {
value: 28,
name: '矮富挫'
}, {
value: 21,
name: '女生'
}]
}
},
methods: {
// 绘图
drawGraph(id) {
// 绘图方法
this.chart = echarts.init(document.getElementById(id))
// 皮肤添加同一般使用方式
this.chart.showLoading()
// 返回到data中
var that = this
// ajax 请求数据
$.ajax({
// 方式
type: "GET",
// 是否异步
async: true,
// 路径||API
url: "xxx",
//返回数据形式为json
dataType: "json",
// 加载成功
success: function(result) {
// 更新初始数据
that.opinionData = result
},
// 加载错误
error: function(errorMsg) {
// alert("请求数据失败!");
console.log(errorMsg)
}
})
// set
this.chart.setOption({
title: {
text: '女生喜欢的男生种类',
subtext: '纯属扯犊子',
x: 'center'
},
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
legend: {
x: 'center',
y: 'bottom',
data: this.opinion // 别忘了this
},
toolbox: {
show: true,
feature: {
mark: {
show: true
},
dataView: {
show: true,
readOnly: false
},
magicType: {
show: true,
type: ['pie']
},
restore: {
show: true
},
saveAsImage: {
show: true
}
}
},
calculable: true,
series: [{
name: '种类',
type: 'pie',
// 内圆半径,外圆半径
radius: [30, 100],
// 位置,左右,上下
center: ['50%', '50%'],
roseType: 'area',
data: this.opinionData, // 别忘了this }]
})
this.chart.hideLoading()
}
},
// keypoint:执行方法
// “将回调延迟到下次 DOM 更新循环之后执行。在修改数据之后立即使用它,然后等待 DOM 更新。”
mounted() {
this.$nextTick(function() {
this.drawGraph('main')
})
}
}
</script>
vuejs中使用echarts的更多相关文章
- Ionic2系列——在Ionic2中使用ECharts
在群里看到有人问怎么在Ionic2中集成ECharts来显示图表.当时答应说写个blog,简单写下步骤. 在TypeScript中如果要使用第三方库,必须要有d.ts,也就是定义文件,没有这个文件的话 ...
- Wabpack系列:在webpack+vue开发环境中使用echarts导致编译文件过大怎么办?
现象,在一个webpack+vue的开发环境中,npm install echarts --save了echarts,然后在vue文件中直接使用 import echarts from 'echart ...
- 接上一篇中记录Echarts进度环使用【不同状态不同进度环颜色及圈内文字】--采用单实例业务进行说明
接上一篇中记录Echarts进度环使用 此处处理不同状态下不同进度环颜色及圈内文字等的相关处理,采用实际案例源码说明 -----------------偶是华丽丽分割线---------------- ...
- 在vue-cli项目中使用echarts
这个示例使用 vue-cli 脚手架搭建 安装echarts依赖 npm install echarts -S 或者使用国内的淘宝镜像: 安装 npm install -g cnpm --regist ...
- 在vue中使用echarts图表
在vue中使用echarts图表 转载请注明出处:https://www.cnblogs.com/wenjunwei/p/9815290.html 安装vue依赖 使用npm npm instal ...
- 在vue中调用echarts中的地图散点图~
首先!当然是在vue中引入echarts! 命令行 npm install echarts --save 在main.js文件中里引入 import echarts from 'ech ...
- Vue+Typescript项目中使用echarts
方案一:推荐 在typescript+Vue的项目中引用echarts,为了加强引用,引入echarts和@types/echarts两个包,一个是工程依赖,一个是声明依赖. npm install ...
- Vue中使用ECharts画散点图加均值线与阴影区域
[本文出自天外归云的博客园] 需求 1. Vue中使用ECharts画散点图 2. 在图中加入加均值线 3. 在图中标注出阴影区域 实现 实现这个需求,要明确两点: 1. 知道如何在vue中使用ech ...
- C#WinForm应用程序中嵌入ECharts图表
C#WinForm应用程序中嵌入ECharts图表 程序运行效果: 下载ECharts: 官网下载ECharts :http://echarts.baidu.com/download.html 或者直 ...
随机推荐
- “<textarea>”内的文字对齐
转载:https://blog.csdn.net/henryzhang2009/article/details/9283803 转: textarea会把开始标签到结束标签里的内容全部原样显示,包括空 ...
- python小练习,利用dict,做一个简单的登录。
'''利用字典实现登录'''users=[{'username':'jerry','pwd':'123456'},{'username':'tom','pwd':'1'}] def login(use ...
- 2017-2018-2 20165221实验二《Java面向对象程序设计》实验报告
JAVA实验二报告 课程:Java程序设计 姓名:谭笑 学号:20165221 实验时间:2018.4.13--2018.4.15 实验2--1 实验内容 实现百分制成绩转成"优.良.中.及 ...
- 浅析 Bag of Feature
Bag of Feature 是一种图像特征提取方法,它借鉴了文本分类的思路(Bag of Words),从图像抽象出很多具有代表性的「关键词」,形成一个字典,再统计每张图片中出现的「关键词」数量,得 ...
- SpringCloud概述
⒈官网说明 SpringCloud是基于SpringBoot提供了一套微服务解决方案,包括服务注册与发现.配置中心.全链路监控.服务网关.负载均衡.熔断器等组件,除了基于Netflix的开源组件做高度 ...
- Vue对变量的监控
Vue对变量的监控 watch: { a(val, oldVal) {//普通的watch监听 if (val == "1") { $('#myModal').modal(); } ...
- seo 优化排名 使用总结
SEO 的优化技巧 随着百度对竞价排名位置的大幅减少,SEO优化将自己的网站在首页上有更好的展示有了更多的可能. 本文将系统阐述SEO优化原理.优化技巧和优化流程. 搜索引擎的优化原理是蜘蛛过来抓取网 ...
- QML 从入门到放弃
发现了一个问题: QQuickView only supports loading of root objects that derive from QQuickItem. If your examp ...
- eMMC基础技术9:分区管理
[转]http://www.wowotech.net/basic_tech/emmc_partitions.html 0.前言 eMMC 标准中,将内部的 Flash Memory 划分为 4 类区域 ...
- python使用pudb调试
pudb是pdb的升级版本 安装 pip3 install pudb 使用方法 在程序文件的开头导入包 from pudb import set_trace set_trace()#断点位置 运行的时 ...