vuejs中使用echarts
来源:互联网 发布:移动电玩城作弊软件 编辑:程序博客网 时间:2024/05/29 08:23
- 试了n种方法之后决定自己撸一个组件,,,,,,,
<!-- 2017.2.11 by vanishment ************* echarts小组件--><style scoped>.content { /*自行添加样式即可*/}#main { /*需要制定具体高度,以px为单位*/ height: 400px;}</style><template> <div class="content"> <div id="main"></div> </div></template><script>// 导入echartsimport 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>
2 0
- vuejs中使用echarts
- vuejs 中如何使用slot
- react中使用echarts
- React中使用ECharts
- angular中使用ECharts
- webpack中使用echarts
- vuejs+element中使用minicolor颜色插件
- Laravel 5.4中使用Vuejs的坑
- Android项目中使用echarts
- vue项目中使用echarts
- 在 webpack 中使用 ECharts
- Extjs中使用Echarts(自适应)
- Vue.js中,使用echarts
- 在Vue项目中使用Echarts(五): Echarts绘制地图
- ECharts官方教程(三)【在webpack中使用 ECharts】
- 如何制作Vuejs组件,并且在项目中使用
- echarts中时间轴单独使用
- QT5中使用Echarts图表组件
- 用异或来交换两个变量是错误的
- Python中Counter计数统计
- 函数极大值
- C语言volatile关键字详解
- 深度理解微信小程序的思想
- vuejs中使用echarts
- 数据库设计
- POJ 3813 Euclid 已被翻译
- 【Unity&角色移动】代码控制重力
- [LeetCode]324. Wiggle Sort II
- Mysql 服务无法启动
- java第十一天
- HDU 4734 F(x) (数位dp)
- AngularJs1学习之--ngModel