vue中使用echarts(vue+vue-cli+axios+jsonp+echarts)
一、安装echarts:
cnpm i echarts -D
二、在vue-cli的main.js文件中引用echarts:
import charts from 'echarts'
Vue.prototype.$echarts = charts
三、echarts详细代码:
echarts.vue:
<template>
<div>
<div id="myChart">
</div>
</div>
</template>
<script>
export default {
methods: {
drawLine(){
// 基于准备好的dom,初始化echarts实例
let myChart = this.$echarts.init(document.getElementById('myChart'));
this.$axios.get("http://127.0.0.1:8000/get_data")
.then(function(res){
// 绘制图表
myChart.setOption({
title: { text: res.data.title },
tooltip: {},
xAxis: {
data: res.data.xAxisData
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: res.data.seriesData
}]
});
})
.catch(function(err){
console.log(err);
})
}
},
mounted(){
this.drawLine();
}
}
</script>
<style>
#myChart{
height: 500px;
}
</style>
四、上面的图表数据通过axios获取,node.js代码如下:
let express = require("express");
let app = express();
app.get("/get_data", function(req, res, next){
res.header("Access-Control-Allow-Origin", "*");
let response = {
title: '在Vue中使用echarts',
xAxisData: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"],
seriesData: [10, 26, 16, 20, 16, 30]
};
res.type('application/json');
res.jsonp(response);
});
app.listen(8000, function(){
console.log("开始执行请求");
});
vue中使用echarts(vue+vue-cli+axios+jsonp+echarts)的更多相关文章
- vue中使用时间插件、vue使用laydate
<input id="time1" readonly="readonly" placeholder="这里选择时间" v-model= ...
- 073——VUE中vuex之使用actions和axios异步初始购物车数据
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue中,使用element ui的弹窗与echarts之间的问题
今天项目中有个需求,就是在页面中点击一个图标,弹出一个抽屉式的弹窗(弹窗是element UI的抽屉),弹窗里边是echarts呈现的数据,当我直接用echarts的时候,报错dom没有获取到: 这就 ...
- vue中简单的数据请求 fetch axios
fetch 不需要额外的安装什么东西,直接就可以使用 fetch(url, { method:'post', headers: { 'Content-Type': 'application/x-www ...
- 013——VUE中多种方式使用VUE控制style样式属性
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【Vue中的坑】Vue打包上传线上报Uncaught SyntaxError: Unexpected token <
今天在vue打包上传线上后,报一下错误,一下就懵了,这可咋整啊,一如既往的想都没想就开始复制错误,上网开搜 Uncaught SyntaxError: Unexpected token < Un ...
- 【Vue中的坑】Vue中的@mouseenter没反应?
在开发中想实现鼠标悬浮,然后发现事件不由被出发,查找资料,发现并不是所有情况都不能用 下面就简单的说一下如何避免这种情况 如果你的悬浮事件是在 a 标签上,那么你直接使用就会出问题,你需要加一个nat ...
- 【Vue中的坑】vue项目中动态绑定src不显示图片解决方法
v-for绑定src的数据如下: data() { return { img_src:"../../assets/images/mirror-service.png" } } 渲染 ...
- 【Vue中的坑】Vue中的修改变量没有效果?
使用箭头函数 this.$forceUpdate();
随机推荐
- 【Python开发】使用pyplot模块绘图
快速绘图 使用pyplot模块绘图¶ matplotlib的pyplot模块提供了和MATLAB类似的绘图API,方便用户快速绘制二维图表.我们先看一个简单的例子: 05-matplotlib/mat ...
- excel经典图表
柱形图: 点击图表,选择数据,添加列 选择展示的列区域数据,编辑水平分类轴,选择按年份统计 效果图: 更改图表类型: 折线图或面积图: 饼图或圆环图: 散点图或气泡图: 组合图: 更改原有图表为组合图 ...
- Python3图片处理头像
一. 简介: Python3图片处理头像右上角类似QQ,微信右上角未读信息效果,其实没有实质作用,只是简单练习. 1. 环境: python3.5 random模块:生成随机数 PIL模块:图像处理模 ...
- oracle查询表的结构
SELECT t.table_name,t.column_name,t.data_type||'('||t.data_length||')', t1.comments FROM User_Tab_Co ...
- 什么是云数据库 HBase 版
云数据库 HBase 版(ApsaraDB for HBase)是基于 Hadoop 的一个分布式数据库,支持海量的PB级的大数据存储,适用于高吞吐的随机读写的场景.目前在阿里内部有数百个集群,100 ...
- javase-整数变量的交换
public class Operator { public static void main(String[] args) { int a=10; int b=20; System.out.prin ...
- [BZOJ4180] 字符串计数
膜一发KsCla巨佬 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5 ...
- html重置模板
新浪的初始化: html,body,ul,li,ol,dl,dd,dt,p,h1,h2,h3,h4,h5,h6,form,fieldset,legend,img { margin: 0; paddin ...
- org.apache.shiro.realm.AuthorizingRealm - No cache or cacheManager properties have been set. Authorization cache cannot be obtained.
项目中用spring shiro来处理权限的问题,但是启动的时候会打印如下日志 org.apache.shiro.realm.AuthorizingRealm - No cache or cacheM ...
- mybatis和spring的整合
Mybatis与Spring的集成 1.配置Spring环境 创建maven工程 pom.xml导入依赖 <project xmlns="http://maven.apache.org ...