最近小编学习了一些Echarts
的使用方法,在这里给大家分享一下
一个动态的柱状轮播图,本想着使用Pyecharts
来实现的,奈何实现不了动态。
看来做酷炫的可视化大屏还是得上Echarts
和D3
。
Echarts
文档地址
https://echarts.apache.org/zh/option.html
可供选择的配置超级多~
还是在Vue.js
这个框架下敲代码。
首先需要安装Node.js
以及NPM
,然后安装Vue.js
及Vue
脚手架3.0
。
# 安装Vue.js
npm install vue
# 安装Vue-cli3脚手架
npm install -g @vue/cli
命令行创建项目。
# 创建名为learn_echarts的项目
vue create learn_echarts
结果如下,选择自定义配置(第三个)。
选择Babel、Router
、CSS Pre-processors
及Linter / Formatter
。
其中「Babel
」负责JS
和Vue
模版语法解析,「Router
」负责前端路由功能。
「CSS Pre-processors
」负责样式文件的预编译,「Linter / Formatter
」负责代码规范。
使用history
模式来创建路由(是),CSS
预处理模式(Less
)。
ESLint
处理模式(标准模式),ESLint
提示(保存时),配置文件处理(放置在独立文件夹),是否将配置保存为预设(否)。
项目创建成功后,在项目文件夹的终端里运行如下命令。
# 运行项目
npm run serve
就可以在http://localhost:8080/访问到如下网页。
修改App.vue
文件内容如下。
template>
<div id="app">
<router-view></router-view>
</div>
</template>
<style lang="less">
</style>
运行项目发现错误,修改eslintrc.js
文件,内容如下。
module.exports = {
root: true,
env: {
node: true
},
extends: [
'plugin:vue/essential',
//'@vue/standard'
],
parserOptions: {
parser: 'babel-eslint'
},
rules: {
//'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
//'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
"space-before-function-paren": 0
}
}
可能是因为代码里有不符合规范的空格存在…
修改router
(路由)文件夹下的index.js
文件。
import Vue from 'vue'
import VueRouter from 'vue-router'
import RankPage from '../views/RankPage.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/rankpage',
component: RankPage
},
]
const router = new VueRouter({
mode: 'history',
routes
})
export default router
在components
文件夹下删除HelloWorld.vue
文件,添加Rank.vue
文件。
<template>
<div class="com-container">
<div class="com-chart" ref="rank_ref">我是rank组件</div>
</div>
</template>
<script>
export default {
data() {
return {
};
},
};
</script>
<style lang="less" scoped></style>
在views
文件夹下删除About.vue
及Home.vue
文件,添加RankPage.vue
文件。
<template>
<div class="com-page">
<rank></rank>
</div>
</template>
<script>
import Rank from "../components/Rank";
export default {
data() {
return {
};
},
components: {
Rank,
},
};
</script>
<style lang="less" scoped>
</style>
这样我们就可以如下地址访问到信息了,即路由创建成功。
码字不易废话两句:有需要学习资料的或者有技术问题交流 “点击” 即可
http://localhost:8080/rankpage(页面显示我是rank组件)
这里记得设置一下全局的CSS
。
在项目的src/assets
路径下新建一个css
文件夹,新建一个全局的global.less
文件。