由testcase資料之分析
阿新 • • 發佈:2019-01-03
一、獲取data來源
1、利用openpyxl從excel表格獲取資料,相較於xlrd,openpyxl可以將表格裡的樣式也傳遞過來的優勢
xlrd ----------------- https://blog.csdn.net/csdnnews/article/details/80878945
openpyxl --------------- https://www.cnblogs.com/zeke-python-road/p/8986318.html
from openpyxl import load_workbook frommatplotlib import pyplot as plt wb = load_workbook('qqqqqq.xlsx') ws = wb.active cols = [] for col in ws.iter_cols(): col = col[1:11] cols.append(col) Casename_list = [] for key in cols[2]: Casename_list.append(key.value) # print(Casename_list) Test_result = [] for key in cols[7]: Test_result.append(key.value)
二、data圖表分析
1、利用matplotlab
存在中文編碼問題:
import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['SimHei'] #用來正常顯示中文標籤 plt.rcParams['axes.unicode_minus']=False #用來正常顯示負號 plt.plot((1,2,3),(4,5,7)) plt.xlabel('橫座標') plt.ylabel('縱座標') plt.show() --------------------- 作者:Yrish 來源:CSDN 原文:https://blog.csdn.net/sinat_29699167/article/details/80029898 版權宣告:本文為博主原創文章,轉載請附上博文連結!
2、echarts ----- https://www.cnblogs.com/a10086/p/9551966.html
A、後臺拼湊資料
class Echarts_html(TemplateView): template_name = "templeate/app01/echarts.html" def get_context_data(self, **kwargs): context = super(Echarts_html, self).get_context_data(**kwargs) aaa= { 'title': { 'text': 'ECharts 入門示例' }, 'tooltip': {}, 'legend': { 'data': ['銷量'] }, 'xAxis': { 'data': [] }, 'yAxis': {}, 'series': [{ 'name': '銷量', 'type': 'bar', 'data': [] }] } articles = Article.objects.all() for item in articles: aaa['xAxis']['data'].append(item.title) aaa['series'][0]['data'].append(item.read_count) context['aaa'] = aaa return context
前臺程式碼,資料處理完畢,前臺直接使用。但是記得加{{xxx|safe}} 否則會被轉義(xss跨站了解下)
<body> <!-- 為ECharts準備一個具備大小(寬高)的Dom --> <div id="main" style="width: 600px;height:400px;"></div> <script type="text/javascript"> // 基於準備好的dom,初始化echarts例項 var myChart = echarts.init(document.getElementById('main')); // 指定圖表的配置項和資料 var option = {{ aaa | safe}}; myChart.setOption(option); </script> </body>
3、前臺js處理資料
class Echarts_html(TemplateView): template_name = "templeate/app01/echarts.html" def get_context_data(self, **kwargs): context = super(Echarts_html, self).get_context_data(**kwargs) context['articles'] = Article.objects.all() return context
前臺程式碼,js處理,注意的一點就是js中陣列push(類似append)必須是字串或者數字,直接"xxxx"轉成字串。
<body> <!-- 為ECharts準備一個具備大小(寬高)的Dom --> <div id="main" style="width: 600px;height:400px;"></div> <script type="text/javascript"> // 基於準備好的dom,初始化echarts例項 var myChart = echarts.init(document.getElementById('main')); // 指定圖表的配置項和資料 var option = { 'title': { 'text': 'ECharts 入門示例' }, 'tooltip': {}, 'legend': { 'data': ['閱讀量'] }, 'xAxis': { 'data': [] }, 'yAxis': {}, 'series': [{ 'name': '閱讀量', 'type': 'bar', 'data': [] }] } {% for item in articles %} option['xAxis']['data'].push("{{ item.title }}") option['series'][0]['data'].push("{{ item.read_count }}") {% endfor %} console.log(option) // 使用剛指定的配置項和資料顯示圖表。 myChart.setOption(option); </script> </body>
三、eg
1、前臺
from django.views.generic.base import TemplateView from .models import * class Echarts_html(TemplateView): template_name = "../templates/eg1.html" def get_context_data(self, **kwargs): context = super(Echarts_html, self).get_context_data(**kwargs) aaa = { 'title': { 'text': 'ECharts 測試示例' }, 'tooltip': {}, 'legend': { 'data': ['銷量'] }, 'xAxis': { 'data': [] }, 'yAxis': {}, 'series': [{ 'name': '銷量', 'type': 'bar', 'data': [] }] } articles = Article.objects.all() for item in articles: aaa['xAxis']['data'].append(item.name) aaa['series'][0]['data'].append(item.read_count) context['aaa'] = aaa return context def post(self,request): print('post') return HttpResponse('post')
2、後臺
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.bootcss.com/echarts/4.2.0-rc.2/echarts.js"></script> </head> <style> #myimg { border: 1px solid red; height: 18px; width: 18px; background-image: url('2.png'); background-position-y: 138px; } </style> <body> <form action="" method="post"> <input type="text"> <input type="submit" value="帶點"> </form> <!-- 為ECharts準備一個具備大小(寬高)的Dom --> <div id="main" style="width: 600px;height:400px;"></div> <script type="text/javascript"> // 基於準備好的dom,初始化echarts例項 var myChart = echarts.init(document.getElementById('main')); // 指定圖表的配置項和資料 var option = {{ aaa | safe}}; myChart.setOption(option); </script> </body> </html>