python信息技术实践之十
可视化面板介绍
应对现在数据可视化的趋势,越来越多企业需要在很多场景(营销数据,生产数据,用户数据)下使用,可视化图表来展示体现数据,让数据更加直观,数据特点更加突出。
完成该项目需要具备以下知识:
-
div + css 布局
-
flex 布局(弹性盒子)
-
Less
-
原生js + jquery 使用
-
rem适配
-
echarts基础
Echarts-体验
官方教程:五分钟上手ECharts
使用步骤:
-
引入echarts 插件文件到html页面中
<script src="echarts.min.js"></script>
-
准备一个具备大小的DOM容器,行内样
<div id="main" style="width: 600px;height:400px;border: 1px solid #f00;"></div>
-
初始化echarts实例对象
在页面写<script> 写代码... </script>
var myChart = echarts.init(document.getElementById('main'));
-
指定配置项和数据(option)
var option = { xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value' }, series: [{ data: [820, 932, 901, 934, 1290, 1330, 1320], type: 'line' }] };
-
将配置项设置给echarts实例对象
myChart.setOption(option);
11-Echarts-基础配置
这是要求同学们知道以下配置每个模块的主要作用干什么的就可以了
需要了解的主要配置:
series
xAxis
yAxis
grid
tooltip
title
legend
color
-
series
-
系列列表。每个系列通过
type
决定自己的图表类型 -
大白话:图标数据,指定什么类型的图标,可以多个图表重叠。
-
-
xAxis:直角坐标系 grid 中的 x 轴
-
boundaryGap: 坐标轴两边留白策略 true,这时候刻度只是作为分隔线,标签和数据点都会在两个刻度之间的带(band)中间。
-
-
yAxis:直角坐标系 grid 中的 y 轴
-
grid:直角坐标系内绘图网格。
-
title:标题组件
-
tooltip:提示框组件
-
legend:图例组件
-
color:调色盘颜色列表
-
图形效果
2.在后台增加对于柱状图的分组查询代码
#成绩:评分,统计
@app.route('/score')
def score():
score=[] #评分集合
num=[] #该评分 有多少个的集合
conn=sqlite3.connect('movie.db')
cursor=conn.cursor() #获取游标对象
data=cursor.execute('SELECT score,count(score) FROM "movie250" GROUP BY score')
for item in data:
score.append(item[0]) #item:表示结果中,每一行;item[0]:第一列
num.append(item[1]) #item[1] 第二列
cursor.close()
conn.close()
return render_template('score.html',score=score,num=num)
3.增加movie.html页面,参考代码如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>豆瓣Top250数据分析</title>
<meta content="" name="descriptison">
<meta content="" name="keywords">
<!-- Favicons -->
<link href="static/assets/img/favicon.png" rel="icon">
<link href="static/assets/img/apple-touch-icon.png" rel="apple-touch-icon">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,600,600i,700,700i,900" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="static/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="static/assets/vendor/icofont/icofont.min.css" rel="stylesheet">
<link href="static/assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
<link href="static/assets/vendor/animate.css/animate.min.css" rel="stylesheet">
<link href="static/assets/vendor/venobox/venobox.css" rel="stylesheet">
<link href="static/assets/vendor/aos/aos.css" rel="stylesheet">
<!-- Template Main CSS File -->
<link href="static/assets/css/style.css" rel="stylesheet">
</head>
<body>
<!-- ======= Header ======= -->
<header id="header">
<div class="container">
<div class="logo float-left">
<h1 class="text-light"><a href="https://www.sqnu.edu.cn"><span>商丘师范</span></a></h1>
<!-- Uncomment below if you prefer to use an image logo -->
<!-- <a href="temp.html"><img src="static/assets/img/logo.png" alt="" class="img-fluid"></a>-->
</div>
<nav class="nav-menu float-right d-none d-lg-block">
<ul>
<li class="active"><a href="/index">首页<i class="la la-angle-down"></i></a></li>
<li><a href="/movie">电影</a></li>
<li><a href="/score">评分</a></li>
<li><a href="/word">词云</a></li>
<li><a href="/team">团队</a></li>
</ul>
</nav><!-- .nav-menu -->
</div>
</header><!-- End Header -->
<!-- ======= Our Team Section ======= -->
<section id="team" class="team">
<div class="container">
<div class="section-title">
<h2>豆瓣电影Top250数据分析</h2>
<p>豆瓣电影电影评分统计图</p>
</div>
<!-- ======= Counts Section ======= -->
<section class="counts section-bg">
<div class="container">
<table class="table table-striped">
<tr>
<td>排名</td>
<td>电影中文名称</td>
<td>电影外国名称</td>
<td>评分</td>
<td>评价人数</td>
<td>一句话概述</td>
<td>其他信息</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
{% for movie in movies %}
<tr>
<td>{{movie[0]}}</td>
<td>
<a href="{{ movie[1] }}" target="_blank">
{{ movie[3] }}
</a>
</td>
<td>{{movie[4]}}</td>
<td>{{movie[5]}}</td>
<td>{{movie[6]}}</td>
<td>{{movie[7]}}</td>
<td>{{movie[8]}}</td>
</tr>
{% endfor %}
</table>
</div>
</section><!-- End Counts Section -->
</div>
</section><!-- End Our Team Section -->
<footer id="footer">
<div class="container">
<div class="copyright">
© Copyright <strong><span>商丘师范学院软件学院</span></strong>. All Rights Reserved
</div>
</div>
</footer><!-- End Footer -->
<a href="#" class="back-to-top"><i class="icofont-simple-up"></i></a>
<!-- Vendor JS Files -->
<script src="static/assets/vendor/jquery/jquery.min.js"></script>
<script src="static/assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="static/assets/vendor/jquery.easing/jquery.easing.min.js"></script>
<script src="static/assets/vendor/php-email-form/validate.js"></script>
<script src="static/assets/vendor/jquery-sticky/jquery.sticky.js"></script>
<script src="static/assets/vendor/venobox/venobox.min.js"></script>
<script src="static/assets/vendor/waypoints/jquery.waypoints.min.js"></script>
<script src="static/assets/vendor/counterup/counterup.min.js"></script>
<script src="static/assets/vendor/isotope-layout/isotope.pkgd.min.js"></script>
<script src="static/assets/vendor/aos/aos.js"></script>
<script src="static/assets/js/main.js"></script>
</body>
</html>
4.项目最终效果如下所示:
- 点赞
- 收藏
- 关注作者
评论(0)