赞
踩
目录
- # 柱状图数据处理
- @app.route("/bar-tick-align-Data")
- def bar_tick_align_Data():
- result=mdal.getCountByScore()
- list1=[i[0] for i in result]
- list2=[i[1] for i in result]
- print(list1)
- print(list2)
- dict1={}
- dict1["data1"]=list1
- dict1["data2"]=list2
- print(dict1)
- return jsonify(dict1)
- # 柱状图网页
- @app.route("/bar-tick-align")
- def bar_tick_align():return render_template("bar-tick-align.html")
- # 饼状图数据处理
- @app.route("/pie-simple-Data")
- def pie_simple_Data():
- result=mdal.getCountByScore()
- list=[{"name":i[0],"value":i[1]} for i in result]
- print(list)
- return jsonify(list)
- # 饼状图网页
- @app.route("/pie-simple")
- def pie_simple():
- return render_template("pie-simple.html")
- # 统计各个评分的电影数量
- def getCountByScore(self):
- sql="select score,count(1) from DoubanMovieType group by
- score"
- return self.chaAll(sql)
- <!--
- 此示例下载自
- https://echarts.apache.org/examples/zh/editor.html?c=bar-tick
- align
- -->
- <!DOCTYPE html>
- <html lang="en" style="height: 100%">
- <head>
- <meta charset="utf-8">
- </head>
- <body style="height: 100%; margin: 0">
- <div id="container" style="height: 100%"></div>
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts/5.5.1/files/dist/e
- charts.min.js"></script>
- <!-- Uncomment this line if you want to dataTool extension
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts/5.5.1/files/dist/e
- xtension/dataTool.min.js"></script>-->
- <!-- Uncomment this line if you want to use gl extension
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts-gl/2/files/dist/ec
- harts-gl.min.js"></script>
- -->
- <!-- Uncomment this line if you want to echarts-stat extension
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts-stat/latest/files/
- dist/ecStat.min.js"></script>
- -->
- <!-- Uncomment this line if you want to echarts-graph-modularity
- extension
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts-graph-modularity/2
- /files/dist/echarts-graph-modularity.min.js"></script>
- -->
- <!-- Uncomment this line if you want to use map
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts/4.9.0/files/map/js
- /world.js"></script>
- -->
- <!-- Uncomment these two lines if you want to use bmap extension
- <script type="text/javascript"
- src="https://api.map.baidu.com/api?v=3.0&ak=YOUR_API_KEY"></sc
- ript>
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts/5.5.1/files/dist/e
- xtension/bmap.min.js"></script>
- -->
- <script
- src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
- <script type="text/javascript">
- $.ajax({
- type:"GET",
- url:"http://127.0.0.1:5000//bar-tick-align-Data",
- dataType:"json",
- success:function(data){
- // 分别修改里面的数据源为动态
- var dom = document.getElementById('container');
- var myChart = echarts.init(dom, null, {
- renderer: 'canvas',useDirtyRect: false
- });
- var app = {};
- var option;
- option = {
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'shadow'
- }
- },
- grid: {
- left: '3%',
- right: '4%',
- bottom: '3%',
- containLabel: true
- },
- xAxis: [
- {
- type: 'category',
- data: data["data1"],
- axisTick: {
- alignWithLabel: true
- }
- }
- ],
- yAxis: [
- {
- type: 'value'
- }
- ],
- series: [
- {
- name: 'Direct',
- type: 'bar',
- barWidth: '60%',
- data: data["data2"]
- }
- ]
- };if (option && typeof option === 'object') {
- myChart.setOption(option);
- }
- window.addEventListener('resize', myChart.resize);
- }
- });
- </script>
- </body>
- </html>
- <!--
- 此示例下载自
- https://echarts.apache.org/examples/zh/editor.html?c=pie-simpl
- e
- -->
- <!DOCTYPE html>
- <html lang="en" style="height: 100%">
- <head>
- <meta charset="utf-8">
- </head>
- <body style="height: 100%; margin: 0">
- <div id="container" style="height: 100%"></div>
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts/5.5.1/files/dist/e
- charts.min.js"></script>
- <!-- Uncomment this line if you want to dataTool extension
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts/5.5.1/files/dist/e
- xtension/dataTool.min.js"></script>
- -->
- <!-- Uncomment this line if you want to use gl extension
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts-gl/2/files/dist/ec
- harts-gl.min.js"></script>
- -->
- <!-- Uncomment this line if you want to echarts-stat extension<script type="text/javascript"
- src="https://registry.npmmirror.com/echarts-stat/latest/files/
- dist/ecStat.min.js"></script>
- -->
- <!-- Uncomment this line if you want to echarts-graph-modularity
- extension
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts-graph-modularity/2
- /files/dist/echarts-graph-modularity.min.js"></script>
- -->
- <!-- Uncomment this line if you want to use map
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts/4.9.0/files/map/js
- /world.js"></script>
- -->
- <!-- Uncomment these two lines if you want to use bmap extension
- <script type="text/javascript"
- src="https://api.map.baidu.com/api?v=3.0&ak=YOUR_API_KEY"></sc
- ript>
- <script type="text/javascript"
- src="https://registry.npmmirror.com/echarts/5.5.1/files/dist/e
- xtension/bmap.min.js"></script>
- -->
- <script
- src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
- <script type="text/javascript">
- $.ajax({
- type:"GET",
- url:"http://127.0.0.1:5000//pie-simple-Data",
- dataType:"json",
- success:function(data){
- var dom = document.getElementById('container');
- var myChart = echarts.init(dom, null, {
- renderer: 'canvas',
- useDirtyRect: false
- });
- var app = {};
- var option;
- option = {
- title: {
- text: '豆瓣电影各评分电影统计',subtext: '',
- left: 'center'
- },
- tooltip: {
- trigger: 'item'
- },
- legend: {
- orient: 'vertical',
- left: 'left'
- },
- series: [
- {
- name: 'Access From',
- type: 'pie',
- radius: '50%',
- data: data,
- emphasis: {
- itemStyle: {
- shadowBlur: 10,
- shadowOffsetX: 0,
- shadowColor: 'rgba(0, 0, 0, 0.5)'
- }
- }
- }
- ]
- };
- if (option && typeof option === 'object') {
- myChart.setOption(option);
- }
- window.addEventListener('resize', myChart.resize);
- }
- });
- </script>
- </body>
- </html>
- <a href="/bar-tick-align">查看柱状图</a>
- <a href="/pie-simple">查看饼状图</a>
- # 数据增删改
- def edit(self,sql):
- try:
- self.openDB()
- result=baoma.execute(sql)
- conn.commit()
- except Exception as e:
- conn.rollback()
- print(e)
- finally:
- self.closeDB()
- return result
- # 添加提交
- @app.route("/DouBanMovieaddSubmit", methods=["POST"])
- def addSubmit():
- try:
- id=request.form.get("id")
- title=request.form.get("title")
- release_date=request.form.get("release_date")
- score=request.form.get("score")
- types=request.form.get("types")
- if eval(id)<0 or type(eval(id))!=int:
- return "id 必须为正整数 <a href='/'>刷新</a>"
- if not id or not title or not release_date or not score or
- not types:
- return "请填写完整信息 <a href='/'>刷新</a>"
- if eval(score)<0 or eval(score)>10:
- return "评分必须在 0-10 之间 <a href='/'>刷新</a>"
- mt=DoubanMovieType(id,title,release_date,score,types)
- result=mdal.insert(mt)
- if result>0:
- return "添加成功 <a href='/'>刷新</a>"
- else:
- return "添加失败 <a href='/'>刷新</a>"
- except UnboundLocalError:
- return "输入数据过长! <a href='/'>刷新</a>"
- except Exception as e:
- print(e)
- return "未知错误!请联系管理员! <a href='/'>刷新</a>"# 修改提交
- @app.route("/updateDouBanMovieSubmit", methods=["POST"])
- def updateSubmit():
- # 修改数据
- try:
- old_id=request.form.get("old_id")
- id=request.form.get("id")
- title=request.form.get("title")
- release_date=request.form.get("release_date")
- score=request.form.get("score")
- types=request.form.get("types")
- if eval(id)<0 or type(eval(id))!=int:
- return "id 必须为正整数 <a href='/'>刷新</a>"
- if not id or not title or not release_date or not score or
- not types:
- return "请填写完整信息 <a href='/'>刷新</a>"
- if eval(score)<0 or eval(score)>10:
- return "评分必须在 0-10 之间 <a href='/'>刷新</a>"
- result=mdal.update(old_id,"id",id)
- result1=mdal.update(old_id,"title",title)
- result2=mdal.update(old_id,"release_date",release_date)
- result3=mdal.update(old_id,"score",score)
- result4=mdal.update(old_id,"types",types)
- if result or result4 or result1 or result2 or result3:
- return "修改成功 <a href='/'>刷新</a>"
- else:
- return "修改失败 <a href='/'>刷新</a>"
- except UnboundLocalError:
- return "输入数据过长! <a href='/'>刷新</a>"
- except Exception as e:
- print(e)
- return "未知错误!请联系管理员! <a href='/'>刷新</a>"
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。