创新实训博客(20)——Vue中使用ECharts进行数据可视化(基本图表部分)
2020-07-14 06:21
555 查看
准备工作
引入echarts、引入echarts-wordcloud
[code]import echarts from 'echarts' require('echarts-wordcloud') require('echarts/theme/roma')
html中设置echarts组件
[code] <el-col :span="15"> <el-card style="margin: 8px"> <div id="trend_dashboard" style="width: 100%; height: 350px" /> </el-card> </el-col>
js设置echarts组件绑定
[code] var that = this that.trend_dashboard = echarts.init(document.getElementById('trend_dashboard'), 'roma') that.top_like_article = echarts.init(document.getElementById('top_like_article'), 'roma') that.top_read_article = echarts.init(document.getElementById('top_read_article'), 'roma') that.top_tag_cloud = echarts.init(document.getElementById('top_tag_cloud'), 'roma') that.top_read_user = echarts.init(document.getElementById('top_read_user'), 'roma') that.top_like_user = echarts.init(document.getElementById('top_like_user'), 'roma') that.top_read_blog = echarts.init(document.getElementById('top_read_blog'), 'roma')
发起请求
[code]// 获取最近的文章点赞量排名 export function getArticleLikingCountRecently() { return request({ url: '/admin/record/getArticleLikingCountRecently', method: 'get', params: { day: 7, page: 1, size: 5 } }) }
返回参数的处理分析
[code]const { data } = response var list = [] for (var i in data) { list.push({ 'name': data[i].name, 'value': data[i].count }) }
设置图表
1. 纵向柱状图和折线图混合
[code]var option = { title: { text: '最近趋势总览' }, grid: { left: '2%', right: '2%', bottom: '2%', containLabel: true }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } }, xAxis: { type: 'category', boundaryGap: false, data: date, axisLabel: { rotate: 50 } }, yAxis: { type: 'value' }, legend: { data: ['累计博客', '新增博客'] }, series: [{ name: '累计博客', data: total, type: 'line', smooth: false, color: '#800000', label: { show: true, position: 'top' } }, { name: '新增博客', data: count, type: 'bar', areaStyle: {}, smooth: false, color: '#008088', label: { show: true, position: 'top' }, markPoint: { data: [ { type: 'max', name: '最大值' }, { type: 'min', name: '最小值' } ] } }] }
2. 横向柱状图
[code]var option = { title: { text: '最热文章' }, tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, grid: { left: '2%', right: '2%', bottom: '2%', containLabel: true }, xAxis: { type: 'value', show: false }, yAxis: { type: 'category', axisLine: { show: false }, axisLabel: { show: false }, axisTick: { show: false }, splitLine: { show: false }, data: title.reverse() }, series: [ { name: '浏览量', type: 'bar', barWidth: 10, data: count.reverse(), color: '#27299a', label: { show: true, position: [0, '-16px'], formatter: function(a) { let num = '' let str = '' num = '0' + (5 - a.dataIndex) str = `${num}-${a.name}` return str } }, showBackground: true, backgroundStyle: { color: '#eeeeee' } } ] }
3. 折线图
[code]var option = { title: { text: '最热个人博客' }, grid: { left: '2%', right: '2%', bottom: '2%', containLabel: true }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } }, xAxis: { type: 'category', boundaryGap: false, data: user, axisLabel: { rotate: 50 } }, yAxis: { type: 'value' }, series: [{ name: '浏览量', data: count, type: 'line', areaStyle: {}, smooth: false, color: '#845316', label: { show: true, position: 'top' } }] }
4. 散点图
[code]var option = { title: { text: '用户点赞数据' }, grid: { left: '2%', right: '2%', bottom: '2%', containLabel: true }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } }, xAxis: { type: 'category', data: user, axisLabel: { rotate: 50 } }, yAxis: { type: 'value' }, series: [{ name: '点赞量', data: count, type: 'effectScatter', color: '#16846e', label: { show: true, position: 'top' } }] }
效果展示
相关文章推荐
- 创新实训博客(21)——Vue中使用ECharts进行数据可视化(进阶部分)
- 创新实训博客(32)——用户画像部分基本统计数据的设计构想
- 记录下遇到到前端VUE 使用ui时间选择器获取后台数据,更新echarts图表的输出显示到html
- CSDN:借助工具对【本博客访问来源】进行数据图表可视化(网友主要来自欧美和印度等)——记录数据来源截止日期20190811
- 在vue中添加Echarts图表的基本使用教程
- vue项目里使用ECharts图表后台返回图表数据
- 创新实训博客(29)——接口调用请求汇总(可视化部分)
- 使用Echarts和Ajax动态加载数据进行大数据可视化
- vue中使用echarts图表自适应的几种基本解决方案
- 创新实训博客(25)——接口调用请求汇总(用户基本操作和历史记录相关部分)
- vue项目中使用Echarts 动态更改图表数据 , Vue 折线图、柱状图等图表动态刷新 ,
- 掌握 Ajax,第 10 部分: 使用 JSON 进行数据传输
- Echarts 动态从后台获取数据进行图表的展示
- 掌握 Ajax,第 10 部分: 使用 JSON 进行数据传输
- 使用R进行数据可视化套路之-茎叶图、盒形图
- iOS开发中大部分App的网络数据交换是基于HTTP协议的。本文将简单介绍在Swift中使用HTTP进行网络请求的几种方法。
- 【云周刊】第127期:数据可视化最强CP登场!DataV接入ECharts图表库
- 掌握 Ajax,第 10 部分: 使用 JSON 进行数据传输
- AJAX(第十部分:使用JSON进行数据传输)
- 使用ECharts绘制可视化图表