def picture_radar(file_path): """ :param file_path:文件路径:str """ birth_hcs = pd.read_csv(file_path) # 使用loc 进行切片, 行:全选 列:选择不连续的用列表包含列名 birth_nien_hcs = birth_hcs.loc[:, [ 'INFANT_ALIVE_AT_REPORT', 'MOTHER_AGE_YEARS', 'CIG_1_TRI', 'MOTHER_PRE_WEIGHT', 'OBSTETRIC_GESTATION_WEEKS', 'INFANT_WEIGHT_GRAMS' ]] birth_nien_hcs = nien_to_nan(birth_nien_hcs, [ 'MOTHER_AGE_YEARS', 'CIG_1_TRI', 'MOTHER_PRE_WEIGHT', 'OBSTETRIC_GESTATION_WEEKS', 'INFANT_WEIGHT_GRAMS' ]) # birth_nien['INFANT_ALIVE_AT_REPORT'] == 'Y' 判断row的值:等于则为True 再使用DataFrame取为True的行 y_hcs = birth_nien_hcs[birth_nien_hcs['INFANT_ALIVE_AT_REPORT'] == 'Y'] n_hcs = birth_nien_hcs[birth_nien_hcs['INFANT_ALIVE_AT_REPORT'] == 'N'] # 按列求平均值,跳过nan, # round(decimals=2): 四舍五入取两位小数 y_mean_hcs = list(y_hcs.mean(skipna=True, axis=0).round(decimals=2)) n_mean_hcs = list(n_hcs.mean(skipna=True, axis=0).round(decimals=2)) print('存活婴儿数据雷达图:', y_mean_hcs, '\n', '死亡婴儿数据雷达图:', n_mean_hcs) schema_hcs = [{ 'name': "母亲平均年龄", 'max': 40 }, { 'name': "母亲平均吸烟数量", 'max': 1.2 }, { 'name': "母亲平均体重", 'max': 200 }, { 'name': "怀孕平均周数", 'max': 40 }, { 'name': "婴儿平均体重", 'max': 3500 }] radar_hcs = Radar('存活婴儿与死亡婴儿数据对比——雷达图(黄彩思)', height=500) radar_hcs.set_radar_component(c_schema=schema_hcs) radar_hcs.add('存活婴儿', [y_mean_hcs], item_color='#2525f5', symbol=None, area_color='#2525f5', area_opacity=0.3, legend_top='bottom', line_width=3) radar_hcs.add('死亡婴儿', [n_mean_hcs], item_color="#f9713c", symbol=None, area_color="#ea3a2e", area_opacity=0.3, legend_top='bottom', line_width=3, legend_text_size=20) radar_hcs.render('radar.html')
def leidatu(): '''雷达图''' schema = [("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000)] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar() radar.config(schema) radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True) radar.add("实际开销", v2, label_color=["#4e79a7"], is_area_show=False) radar.render('./info/雷达图.html')
def drawRadar(title, data, savepath='./results'): if not os.path.exists(savepath): os.mkdir(savepath) radar = Radar(title, title_pos='center') radar.use_theme('essos') values = [j for i, j in data.items()] sum_ = sum(values) / (len(values) // 2) schema = [(i, sum_) for i, j in data.items()] values = [values] radar.config(schema) radar.add("", values, is_splitline=True, is_axisline_show=True, radar_text_size=20) radar.render(os.path.join(savepath, '%s.html' % title))
def test_radar_default_schema(): schema = [ ("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000) ] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar("雷达图示例") radar.config(schema) radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True) radar.add("实际开销", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode='single') radar.render()
def Chart1(): # 第一张图,绘制的是两支球队的对比图,只用到了第一轮的数据 sheet1 = book.sheets['turn1'] _list1 = [] _list2 = [] # 从 sheet 中获取数据 cells1 = sheet1.range('B4:J4').value # 第 1 支球队 cells2 = sheet1.range('B3:J3').value # 第 2 支球队 for cell1, cell2 in zip(cells1, cells2): _list1.append(cell1) _list2.append(cell2) v1 = [_list1] v2 = [_list2] chart = Radar("进攻属性", title_pos='center') schema = [ ("评分", 10), # B:rate ("传球", 550), # C:passes ("传球成功率", 0.9), # D:passSucc ("控球率", 0.6), # E: ("射门", 15), # F: ("拦截", 15), # G: ("解围", 20), # H: ("抢断", 20), # I: ("争顶成功", 20), # J: ] chart.config(schema) chart.add("曼城", v1, item_color="#330f67") chart.add("利物浦", v2, legend_orient='vertical', legend_pos='left') return chart
def create_radar(self, v): #绘制雷达图 radar = Radar(self.TITLE_TEXT, self.TITLE_SUBTEXT) schema = [ ("口头语言", 5), ("原创性", 5), ("问题敏感度", 5), ("逻辑思维", 5), ("数学能力", 5), ("人际沟通", 5) ] radar.config(schema) v1 = [v] v2 = [[2,3,5,4,2,1]] radar.add( "第一次推荐输入", v1, is_splitline = True, is_axisline_show = True, is_label_show=True, area_opacity = 0.2 ) radar.add( "第二次推荐输入", v2, label_color=["#4e79a7"], is_area_show= False, legend_selectedmode='single', area_opacity = 0.5 ) snippet = TRANSLATOR.translate(radar.options) options = snippet.as_snippet() return options
def visual(self, array): schema = [('得分', 35), ('篮板', 20), ('助攻', 15), ('抢断', 5), ('盖帽', 5)] radar = Radar() radar.config(schema) for player, data in array.items(): radar.add(player, data, is_splitline=True, is_axisline_show=True) radar.render('player.html')
def drawRadar(title, data, savepath='./results'): radar = Radar(title) values = [[data[i][1] for i in range(len(data))]] schema = [(data[i][0], 500) for i in range(len(data))] radar.config(schema) radar.add('', values, is_splitline=True, is_axisline_show=True) radar.render(os.path.join(savepath, '%s.html' % title))
def __draw_radar_core__(city, data, color): c_schema = [{ "name": "PM2.5\nmax=500μg/m3", "max": 500, "min": 0 }, { "name": "PM10\nmax=1500μg/m3", "max": 1500, "min": 0 }, { "name": "SO2\nmax=100μg/m3", "max": 100 }, { "name": "NO2\nmax=200μg/m3", "max": 200 }, { "name": "CO\nmax=5.0mg/m3", "max": 5 }, { "name": "O3\nmax=200μg/m3", "max": 200, "min": 0 }] radar = Radar(background_color='#333') radar.config( c_schema=c_schema, shape='polygon', radar_text_color="#FFF", ) # radar.use_theme("dark") radar.add( city, data, is_area_show=True, area_color=color, #'#F0891F', area_opacity=0.3, line_curve=0.1, line_opacity=0, symbol=None, legend_text_color='#FFF', # legend_orient='vertical', legend_top='4%', legend_pos='25%', legend_text_size=15, legend_selectedmode=False, label_color=[color] #,'#3F4A97','#F05F8D','#6A9EA3'] ) radar.render() radar.render(city + '雷达图.jpeg')
def test_radar_user_define_schema_single(): radar = Radar("雷达图示例") radar.config(c_schema=c_schema, shape='circle') radar.add("北京", value_bj, item_color="#f9713c", symbol=None) radar.add("上海", value_sh, item_color="#b3e4a1", symbol=None, legend_selectedmode='single') html_content = radar._repr_html_() assert 'single' in html_content assert 'multiple' not in html_content
def test_radar_user_define_schema_single(): radar = Radar("雷达图示例") radar.config(c_schema=c_schema, shape='circle') radar.add("北京", value_bj, item_color="#f9713c", symbol=None) radar.add("上海", value_sh, item_color="#b3e4a1", symbol=None, legend_selectedmode='single') html_content = radar._repr_html_() assert 'single' in html_content assert 'multiple' not in html_content
def test_radar_default_schema(): schema = [ ("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000) ] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar("雷达图示例") radar.config(schema) radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True) radar.add("实际开销", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode='single') radar.render()
def test_radar_user_define_schema_single(): radar = Radar("雷达图示例") radar.set_radar_component(c_schema=c_schema, shape="circle") radar.add("北京", value_bj, item_color="#f9713c", symbol=None) radar.add( "上海", value_sh, item_color="#b3e4a1", symbol=None, legend_selectedmode="single", ) html_content = radar._repr_html_() assert "single" in html_content assert "multiple" not in html_content
def test_radar_user_define_schema_multiple(): radar = Radar("雷达图示例") radar.config(c_schema=c_schema, shape="circle") radar.add("北京", value_bj, item_color="#f9713c", symbol=None) radar.add("上海", value_sh, item_color="#b3e4a1", symbol=None) html_content = radar._repr_html_() assert "multiple" in html_content assert "single" not in html_content
def draw_radar_per_scenario(self, model, integrated_folders, integrated_means, original_folders, original_means, scenario): # 绘制汇总体雷达图 title = u'性能指标对比汇总' schema = [] for counter in self.analyzer.get_counters_list(): counter_txt = self.analyzer.translate(counter) schema.append( (counter_txt, self.analyzer.get_radar_schema(counter))) if scenario.startswith(STARTTIME): counter_txt = self.analyzer.translate(STARTTIME) schema.append( (counter_txt, self.analyzer.get_radar_schema(STARTTIME))) # 获取启动时间时间 original_launch = np.array( self.analyzer.get_launch_time( original_folders, self.analyzer.get_package_name(), self.analyzer.get_activity_name())) integrated_launch = np.array( self.analyzer.get_launch_time( integrated_folders, self.analyzer.get_package_name(), self.analyzer.get_activity_name())) # 计算启动均值并汇总 original_means.append(original_launch.mean()) integrated_means.append(integrated_launch.mean()) collect_duration_mean(self.analyzer.summary_values, model, scenario, self.analyzer.get_test_type(0), 'launch', np.array(original_launch), STARTTIME) collect_duration_mean(self.analyzer.summary_values, model, scenario, self.analyzer.get_test_type(1), 'launch', np.array(integrated_launch), STARTTIME) v0 = [np.round(np.array(original_means), decimals=2).tolist()] v1 = [np.round(np.array(integrated_means), decimals=2).tolist()] radar = Radar(title, title_pos='center') # radar.use_theme('roma') radar.config(schema) radar.add(self.analyzer.translate(self.analyzer.get_test_type(0)), v0, legend_top='bottom', is_splitline=True, is_axisline_show=True, is_more_utils=False) radar.add(self.analyzer.translate(self.analyzer.get_test_type(1)), v1, legend_top='bottom', item_color="#4e79a7", is_area_show=False) return radar
def radar_demo(self): # 雷达图 from pyecharts import Radar radar = Radar('雷达图', subtitle='一年的降水量与蒸发量') # 由于雷达图传入的数据得为多维数据,所以这里需要做一下处理 radar_data1 = [[ 2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3 ]] radar_data2 = [[ 2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3 ]] # 设置column的最大值,为了雷达图更为直观,这里的月份最大值设置有所不同 schema = [("Jan", 5), ("Feb", 10), ("Mar", 10), ("Apr", 50), ("May", 50), ("Jun", 200), ("Jul", 200), ("Aug", 200), ("Sep", 50), ("Oct", 50), ("Nov", 10), ("Dec", 5)] # 传入坐标 radar.config(schema) radar.add("降水量", radar_data1) # 一般默认为同一种颜色,这里为了便于区分,需要设置item的颜色 radar.add("蒸发量", radar_data2, item_color="#1C86EE") radar.render('radar.html')
def test_radar_user_define_schema_multiple(): radar = Radar("雷达图示例") radar.config(c_schema=c_schema, shape="circle") radar.add("北京", value_bj, item_color="#f9713c", symbol=None) radar.add("上海", value_sh, item_color="#b3e4a1", symbol=None) html_content = radar._repr_html_() assert "multiple" in html_content assert "single" not in html_content
def ReadOther(): attr = ["城市社区服务", "环保项目", "帮扶活动", "文体活动", "安全医疗", "法律宣传讲座培训", "其他"] value = [373257, 159648, 212721, 246070, 143465, 120205, 93256] funnel = Funnel("项目类别统计", width='100%', height='100%', title_pos='center', title_text_size=16, title_color='#3B5077') funnel.add("类别统计", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff", label_text_size=8, legend_orient="vertical", legend_pos="left", legend_text_size=10) name = [] value = [] with open('data/全国院校统计前100.csv', 'r', encoding='utf-8') as file: reader = csv.reader(file) for row in reader: name.append(row[2]) value.append(row[1]) wordcloud = WordCloud(width='120%', height='100%') wordcloud.add("", name, value, word_size_range=[8, 30]) schema = [ ("博士研究生", 1000000), ("硕士研究生", 1000000), ("大学本科", 1000000), ("大学专科", 1000000), ("中等专科", 1000000), ("技工学校", 1000000), ("高中", 1000000), ("初中", 1000000), ("职业高中", 1000000), ("小学", 1000000), ] v1 = [[9979, 48300, 716519, 448358, 118656, 36065, 600168, 697599, 54160, 270191]] v2 = [[863336, 462984, 953627, 646927, 234893, 170111, 354992, 241914, 158316, 84504]] radar = Radar(width='100%', height='110%') radar.config(schema) radar.add("实际人数分布", v1, is_splitline=True, is_axisline_show=True, label_text_size=8, legend_orient="vertical") radar.add("人数比例分布", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode='single', legend_pos="right", legend_text_size=10, legend_orient="vertical") attr = ["群众", "中国少年先锋队队员", "无党派民主人士", "台湾民主自治同盟盟员", "九三学社社员", "中国致公党党员", "中国农工民主党党员", "中国民主促进会会员", "中国民主建国会会员", "中国民主同盟盟员", "中国国民党革命委员会会员", "中国共产主义青年团团员", "中国共产党预备党员", "中国共产党党员"] v2 = [34688546, 2725751, 95275, 2180, 713840, 3787, 30049, 7356, 7278, 14952, 21065, 12621879, 294148, 6089445] pie = Pie(width='100%', height='90%', title_pos='center', title_text_size=10) pie.add("政治面貌统计", attr, v2, center=[50, 50], is_random=True, radius=[10, 80], rosetype="area", is_legend_show=True, is_label_show=False, legend_pos="left", legend_text_size=10, legend_orient="vertical") attr = ['2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018'] line = Line(width='100%', height='100%') line.add("志愿者数增长", attr, [1, 59580, 532707, 258196, 26194, 628465, 311171, 1970707, 1539836, 2807952, 6566130, 6775399, 36504414, 7408478], mark_line=["average"]) line.add("团体增长", attr, [371, 485, 471, 924, 798, 1266, 2887, 4963, 4848, 7781, 24203, 15936, 25280, 5376], mark_line=["average"]) line.add("项目增长", attr, [10, 6, 3, 94, 125, 152, 210, 802, 3209, 10937, 58426, 166609, 341083, 203931], mark_line=["average"], legend_text_size=10, yaxis_label_textsize=8, yaxis_margin=2) return funnel, wordcloud, radar, pie, line
def scores_of_bread(data): star = data['Star'].mean() taste = data['Taste'].mean() environ = data['Environment'].mean() service = data['Service'].mean() ave = (taste + environ + service) / 3 result_show = [star, taste, environ, service, ave] config_info = [('星级', 50), ('口味', 10), ('环境', 10), ('服务', 10), ('综合', 10)] scores_fig1 = Radar('综合评分情况') scores_fig1.config(config_info) scores_fig1.add('', [result_show]) scores_fig1.render(os.path.join(data_out, 'scores1_of_bread.html')) result = pd.DataFrame(columns=data.columns) for index, item in enumerate(data['Taste']): if item == data['Taste'].max(): # print('口味最好:\n', data.loc[index]) # print(data.loc[index].info()) result = result.append(data.loc[index]) for index, item in enumerate(data['Environment']): if item == data['Environment'].max(): # print('环境最佳:\n', data.loc[index]) result = result.append(data.loc[index]) for index, item in enumerate(data['Service']): if item == data['Service'].max(): # print('服务最棒:\n', data.loc[index]) result = result.append(data.loc[index]) result.to_csv(os.path.join(data_out, 'result_of_best.csv'), encoding='utf-8-sig') print( '最昂贵的菜系:%s' % data.groupby('Cuisine')['Per_Consumption'].mean().idxmax(), '人均:%.2f元' % data.groupby('Cuisine')['Per_Consumption'].mean().max()) print('最受欢迎的菜系:%s' % data.groupby('Cuisine')['Comments'].mean().idxmax(), '平均有:%d条评论' % data.groupby('Cuisine')['Comments'].mean().max()) data['ave'] = round( (data['Taste'] + data['Environment'] + data['Service']) / 3, 2) scores_fig2 = Scatter('综合评分与餐厅星级关系') scores_fig2.add('综合评分', data['Star'].values, data['ave'].values) scores_fig2.render(os.path.join(data_out, 'scores2_of_bread.html'))
def DrawRadar(city_name): schema = [('最高气温', 45), ('气压', 1500), ('湿度', 100), ('最低气温', 45), ('PM2.5', 200)] data = qr.get_data(city_name) values = [[ int(data['Htemperature']), int(data['QY']), int(data['SD'].strip('%')), int(data['Ltemperature']), int(data['pm25']) ]] radar = Radar() radar.config(schema) radar.add('%s天气信息' % city_name, values, is_splitline=True, is_axisline_show=True) radar.render('weatherRadar.html')
def radar_chart(): schema = [("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000)] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar() radar.config(schema, shape='circle', is_area_show=True, area_opacity=0.1, area_color="#fff", radar_text_color="#fff") radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True, symbol=None, item_color="#b3e4a1", line_width=2) radar.add("实际开销", v2, label_color=["#4e79a7"], symbol=None, line_width=2) return radar
def draw(self): for mode in ["slam", "alignment", "alignment2", "rt"]: page = Page(page_title="(%s) SLAM Performance Test Report" % mode) num = len(self.data_standard[mode]["kf_num"]) schema = [("kf数量", 3000 * num), ("lost数量", 30 * num), ("分段数", 10 * num), ("3D点数量", 70000 * num), ("耗时", 4000 * num)] v1 = [[ s2i(self.data_standard[mode]["kf_num"]), s2i(self.data_standard[mode]["lost_num"]), sum(self.data_standard[mode]["section_num"]), s2i(self.data_standard[mode]["mp_num"]), s2i(self.data_standard[mode]["time"]), 19000 ]] v2 = [[ s2i(self.data_develop[mode]["kf_num"]), s2i(self.data_develop[mode]["lost_num"]), sum(self.data_develop[mode]["section_num"]), s2i(self.data_develop[mode]["mp_num"]), s2i(self.data_develop[mode]["time"]), 19000 ]] radar = Radar() radar.config(schema) radar.add( sys.argv[1].split("_")[-2], v1, is_splitline=True, is_axisline_show=True, ) radar.add(sys.argv[2].split("_")[-2], v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode='normal') page.add(radar) for key in self.performance_criteria: draw_in_type(self.data_standard[mode][key], self.data_develop[mode][key], self.standard_set_names[mode], page, key) page.render(path="../Reports/SLAM_Performance_%s.html" % mode)
def radar_map(): kwargs = dict(label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='right', legend_top='center', legend_text_size=18, label_text_size=18, label_emphasis_textsize=18, xaxis_name_size=18, xaxis_label_textsize=18, xaxis_margin=5, xaxis_line_width=2, yaxis_name_size=18, yaxis_label_textsize=18, yaxis_line_width=2, is_splitline_show=False, is_xaxis_boundarygap=True, is_toolbox_show=False, line_width=3) timeline = Timeline(timeline_bottom=0, width=1400, height=700, timeline_symbol_size=10) for year in value_base.current_years: radar_map = Radar('雷达图', title_pos='center', title_text_size=30, title_top=10) for area in value_base.current_areas: data = [[]] for index in value_base.current_indexs: for veti_data in value_base.veti_data_dict[year]: if veti_data[0] == area: data[0].append( round(veti_data[value_base.index_num_dict[index]], 2)) radar_map.set_radar_component(schema=value_base.radar_schema) radar_map.add(area, data, **kwargs) timeline.add(radar_map, year) result = str(value_base.output_dir + u"雷达图.html") timeline.render(result)
def plotSynthesize(): schema = [("口味", 100), ("环境", 100), ("服务", 100), ("人均", 250), ("星级", 50)] list_shopName = [ '天素无界蔬食餐厅', '梵', '肉魁屋烧肉酒场', '锋哥的馆子', '淮扬府·游园京梦', '随遇·青涩小馆·之·未央28楼', '串一火锅', '美阳馆', '张老板的店', '板•菋' ] page = Page() for i in range(len(list_shopName)): list_select = foodRangingCity("西安", list_shopName[i]) print(list_shopName[i], list(list_select[0])[1:]) v2 = [list(list_select[0])[1:]] radar = Radar() radar.config(schema) radar.add(list_select[0][0], v2, label_color=["red"], is_area_show=False, legend_selectedmode='single') page.add(radar) page.render("综合评价.html")
def draw(datas, keys, names): for mode in ["slam", "alignment", "alignment2", "rt", "slamwithdb"]: page = Page(page_title="(%s) SLAM Performance Test Report" % mode) radar = Radar() num = len(names[mode]) schema = [("kf数量", 10000 * num), ("lost数量", 100 * num), ("分段数", 10 * num), ("3D点数量", 70000 * num), ("耗时", 4000 * num)] radar.config(schema) for data in datas: values = [[ s2i(datas[data][mode]["kf_num"]), s2i(datas[data][mode]["lost_num"]), sum(datas[data][mode]["section_num"]), s2i(datas[data][mode]["mp_num"]), s2i(datas[data][mode]["time"]) ]] radar.add(data, values, is_splitline=True, is_axisline_show=True, is_area_show=False, is_label_show=True, legend_selectedmode='normal') page.add(radar) for key in keys: bar = Bar(key) for data in datas: # mark_point = ["max", "min"] bar.add(data, names[mode], datas[data][mode][key], is_datazoom_show=True, is_label_show=True, is_random=False, is_more_utils=True, mark_line=["average"]) page.add(bar) page.render(path="../Reports/SLAM_Performance_%s.html" % mode)
def echart1(request): template = loader.get_template('ewpyecharts.html') sql_s = "select typen, count(*) f1, sum(order_m) as f2, sum(status) f3, max(order_m) f4, avg(order_m) f5 from myechart_ewsales group by typen" columns_s = ["typen", "f1", "f2", "f3", "f4", "f5"] # index_col_s = "f1" df = pd.read_sql(sql_s, connection, columns=columns_s) df = df.sort_values(by='f1', ascending=False) # f1 数量, f2 金额, f2 成功率, f4 最大金额, F5 平均金额 # old_width = pd.get_option('display.max_colwidth') # pd.set_option('display.max_colwidth', -1) # df.to_html('files.html', escape=False, index=False, sparsify=True, border=0, index_names=False, header=False) # pd.set_option('display.max_colwidth', old_width df1 = list(df['typen']) df2 = df[['f1', 'f2', 'f3', 'f4', 'f5']] # 用于调整雷达各维度的范围大小 c_schema = [{ "name": "数量201910", "max": df['f1'].max(), "min": -1 }, { "name": "金额2019", "max": df['f2'].max(), "min": -1 }, { "name": "成功率", "max": df['f3'].max(), "min": -1 }, { "name": "最大金额", "max": df['f4'].max(), "min": -1 }, { "name": "平均金额", "max": df['f5'].max(), "min": -1 }] # # 画图 radar = Radar() radar.config(c_schema=c_schema) radar.add(df1[0], df2[0:1].values.tolist(), item_color="#f9713c", symbol=None, area_color="#ea3a2e", area_opacity=0.1, legend_top='bottom', line_width=3) radar.add(df1[1], df2[1:2].values.tolist(), item_color='#2525f5', symbol=None, area_color='#2525f5', area_opacity=0.1, legend_top='bottom', legend_text_size=20, line_width=3) radar.add(df1[2], df2[2:3].values.tolist(), item_color='#112535', line_width=3) radar.add(df1[3], df2[3:4].values.tolist(), item_color='#991125', line_width=3) radar.add(df1[4], df2[4:5].values.tolist(), item_color='#1125b9', line_width=3) radar.render("Rader.html") context = dict(myechart=radar.render_embed(), host=REMOTE_HOST, script_list=radar.get_js_dependencies()) html_out = template.render(context, request) # attr = ["衬衫", "羊毛衫", "始祖鸟", "裤子", "高跟鞋", "袜子"] # v1 = [5, 20, 36, 10, 75, 90] # v2 = [10, 25, 8, 60, 20, 80] # bar1 = Bar("柱状图数据堆叠示例") # bar1.add("商家A", attr, v1, is_stack=True) # bar1.add("商家B", attr, v2, is_stack=True) # # context = dict( # bar=bar1.render_embed(), # host=REMOTE_HOST, # script_list=bar.get_js_dependencies() # ) # return HttpResponse(template.render(context, request)) return HttpResponse(html_out)
def test_more(): page = Page() # line attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] line = Line("折线图示例") line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"]) line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"]) page.add(line) # pie attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图-圆环图示例", title_pos='center') pie.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='left') page.add(pie) # kline v1 = [[2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03], [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07], [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82], [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78], [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22]] kline = Kline("K 线图示例") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1) page.add(kline) # radar schema = [("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000)] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar("雷达图示例") radar.config(schema) radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True) radar.add("实际开销", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode='single') page.add(radar) # scatter3d import random data = [[ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100) ] for _ in range(80)] range_color = [ '#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026' ] scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600) scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color) page.add(scatter3D) # wordcloud name = [ 'Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications', 'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp', 'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham', 'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break' ] value = [ 10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112, 965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265 ] wordcloud = WordCloud(width=1300, height=620) wordcloud.add("", name, value, word_size_range=[30, 100], rotate_step=66) page.add(wordcloud) # liquid liquid = Liquid("水球图示例") liquid.add("Liquid", [0.6]) page.add(liquid) page.render()
radius_data=radius, type='barRadius', is_stack=True) polar.add("C", [1, 2, 3, 4, 1, 2, 5], radius_data=radius, type='barRadius', is_stack=True) polar.show_config() polar.render(path='./data/03-04极坐标.html') # 雷达图 schema = [("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000)] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar() radar.config(schema) radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True) radar.add("实际开销", v2, label_color=["#4e79a7"], is_area_show=False) radar.show_config() radar.render(path='./data/03-05雷达图.html') """ #支持保持成各种格式,但是会有问题 bar = Bar("我的第一个图表", "这里是副标题") bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90]) # bar.print_echarts_options() bar.render(path='snapshot.html') bar.render(path='snapshot.png') bar.render(path='snapshot.pdf') """
2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22]] kline = Kline("K 线图示例") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1) page.add(kline) # radar schema = [("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000)] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar('雷达图示例') radar.config(schema) radar.add('预算分配', v1, is_splitline=True, is_axisline_show=True, line_color='red') radar.add('实际开销', v2, label_color=['#4e79a7'], is_area_show=False) page.add(radar) page.render()
def test_radar(): # radar_0 schema = [("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000)] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar("雷达图示例") radar.config(schema) radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True) radar.add("实际开销", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode='single') radar.show_config() radar.render() # radar_1 value_bj = [ [55, 9, 56, 0.46, 18, 6, 1], [25, 11, 21, 0.65, 34, 9, 2], [56, 7, 63, 0.3, 14, 5, 3], [33, 7, 29, 0.33, 16, 6, 4], [42, 24, 44, 0.76, 40, 16, 5], [82, 58, 90, 1.77, 68, 33, 6], [74, 49, 77, 1.46, 48, 27, 7], [78, 55, 80, 1.29, 59, 29, 8], [267, 216, 280, 4.8, 108, 64, 9], [185, 127, 216, 2.52, 61, 27, 10], [39, 19, 38, 0.57, 31, 15, 11], [41, 11, 40, 0.43, 21, 7, 12], [64, 38, 74, 1.04, 46, 22, 13], [108, 79, 120, 1.7, 75, 41, 14], [108, 63, 116, 1.48, 44, 26, 15], [33, 6, 29, 0.34, 13, 5, 16], [94, 66, 110, 1.54, 62, 31, 17], [186, 142, 192, 3.88, 93, 79, 18], [57, 31, 54, 0.96, 32, 14, 19], [22, 8, 17, 0.48, 23, 10, 20], [39, 15, 36, 0.61, 29, 13, 21], [94, 69, 114, 2.08, 73, 39, 22], [99, 73, 110, 2.43, 76, 48, 23], [31, 12, 30, 0.5, 32, 16, 24], [42, 27, 43, 1, 53, 22, 25], [154, 117, 157, 3.05, 92, 58, 26], [234, 185, 230, 4.09, 123, 69, 27], [160, 120, 186, 2.77, 91, 50, 28], [134, 96, 165, 2.76, 83, 41, 29], [52, 24, 60, 1.03, 50, 21, 30], [46, 5, 49, 0.28, 10, 6, 31] ] value_sh = [ [91, 45, 125, 0.82, 34, 23, 1], [65, 27, 78, 0.86, 45, 29, 2], [83, 60, 84, 1.09, 73, 27, 3], [109, 81, 121, 1.28, 68, 51, 4], [106, 77, 114, 1.07, 55, 51, 5], [109, 81, 121, 1.28, 68, 51, 6], [106, 77, 114, 1.07, 55, 51, 7], [89, 65, 78, 0.86, 51, 26, 8], [53, 33, 47, 0.64, 50, 17, 9], [80, 55, 80, 1.01, 75, 24, 10], [117, 81, 124, 1.03, 45, 24, 11], [99, 71, 142, 1.1, 62, 42, 12], [95, 69, 130, 1.28, 74, 50, 13], [116, 87, 131, 1.47, 84, 40, 14], [108, 80, 121, 1.3, 85, 37, 15], [134, 83, 167, 1.16, 57, 43, 16], [79, 43, 107, 1.05, 59, 37, 17], [71, 46, 89, 0.86, 64, 25, 18], [97, 71, 113, 1.17, 88, 31, 19], [84, 57, 91, 0.85, 55, 31, 20], [87, 63, 101, 0.9, 56, 41, 21], [104, 77, 119, 1.09, 73, 48, 22], [87, 62, 100, 1, 72, 28, 23], [168, 128, 172, 1.49, 97, 56, 24], [65, 45, 51, 0.74, 39, 17, 25], [39, 24, 38, 0.61, 47, 17, 26], [39, 24, 39, 0.59, 50, 19, 27], [93, 68, 96, 1.05, 79, 29, 28], [188, 143, 197, 1.66, 99, 51, 29], [174, 131, 174, 1.55, 108, 50, 30], [187, 143, 201, 1.39, 89, 53, 31] ] c_schema = [{"name":"AQI", "max": 300, "min": 5}, {"name":"PM2.5", "max": 250, "min": 20}, {"name":"PM10", "max":300, "min": 5}, {"name":"CO", "max":5}, {"name":"NO2", "max":200}, {"name":"SO2", "max":100}] radar = Radar("雷达图示例") radar.config(c_schema=c_schema, shape='circle') radar.add("北京", value_bj, item_color="#f9713c", symbol=None) radar.add("上海", value_sh, item_color="#b3e4a1", symbol=None, legend_selectedmode='signle') radar.show_config() radar.render() # radar_2 radar = Radar("雷达图示例") radar.config(c_schema=c_schema, shape='circle') radar.add("北京", value_bj, item_color="#f9713c", symbol=None) radar.add("上海", value_sh, item_color="#b3e4a1", symbol=None) radar.show_config() radar.render()
#2个系列的5个维度的数据 value1 = [[99,69,102,105,104,113,111,98,96,89,86,92]] #用于调整雷达各维度的范围大小 c_schema= [{"name": "一月", "max": 120, "min": 0}, {"name": "二月", "max": 120, "min": 0}, {"name": "三月", "max": 120, "min": 0}, {"name": "四月", "max": 120, "min": 0}, {"name": "五月", "max": 120, "min": 0}, {"name": "六月", "max": 120, "min": 0}, {"name": "七月", "max": 120, "min": 0}, {"name": "八月", "max": 120, "min": 0}, {"name": "九月", "max": 120, "min": 0}, {"name": "十月", "max": 120, "min": 0}, {"name": "十一月", "max": 120, "min": 0}, {"name": "十二月", "max": 120, "min": 0}] radar = Radar("ABCDE的雷达图",title_pos='left') radar.config(c_schema=c_schema,radar_text_size=20) radar.add(" ", value1, item_color='#2525f5', symbol=None,aarea_opacity=0.3, legend_top='bottom',line_width=3) radar.render("Rader.html") #f9713c attr=['生产过程火灾爆炸事故','生产过程中毒伤害事故','储存过程中重特大事故', '运输过程中火灾爆炸事故','运输过程中毒伤害事故','使用、销售过程中造成的重特大伤亡事故', '储罐、管道重特大泄漏事故的应急救援','运输车辆、船舶重特大泄漏事故的应急救援','危险化学品其他重特大事故'] v1=[94,55,27,19,15,15,7,8,19] #v2=[85,24,39,80,27] pie=Pie(" ",title_pos='left',width=1000,height=300) pie.add('1',attr,v1, center=[50,60],radius=[30,75],is_label_show=True)
def CreateCharts(): page = Page() app = xw.App(visible=False, add_book=False) app.display_alerts = False app.screen_updating = False book = app.books.open(filepath) sheet = book.sheets['centre-forward'] _list1 = [] _list2 = [] # 从 excel 中获取数据 cells1 = sheet.range('F2:M2').value # 第 1 支球队 cells2 = sheet.range('F3:M3').value # 第 2 支球队 # print(data1) for cell1, cell2 in zip(cells1, cells2): _list1.append(cell1) _list2.append(cell2) v1 = [_list1] v2 = [_list2] chart = Radar("进攻属性") schema = [ ("评分", 10), ("射门", 4), ("射正率", 0.5), ("goalProp",0.4), ("传球", 35), ("关键传球", 2), ("传球准确率(%)",100 ), ("过人", 1), # ("越位", 5), ] chart.config(schema) chart.add("菲尔米诺", v1, item_color="#330f67") chart.add("阿圭罗", v2) page.add(chart) # 玫瑰图 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v2 = [19, 21, 32, 20, 20, 33] chart = Pie("饼图-玫瑰图示例", title_pos='center') chart.add("商品A", attr, v2, is_random=True, radius=[30, 75], rosetype='area', is_legend_show=False, is_label_show=True) page.add(chart) # 雷达图 schema = [ ("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000) ] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] v3 = [[3000, 9000, 27890, 33000, 43098, 18000]] v4 = [[3890, 12098, 29022, 32000, 41000, 20000]] chart = Radar("雷达图-默认指示器") chart.config(schema) chart.add("预算分配", v1) chart.add("实际开销", v2) chart.add("ddd", v3) chart.add("fff", v4) page.add(chart) app.kill() return page
def echart04(request): template = loader.get_template('ewpyecharts.html') cursor = connection.cursor() query_sql = "select typen, count(*) f1, sum(order_m) as f2, sum(status) f3, max(order_m) f4, avg(order_m) f5 from myechart_ewsales group by typen" cursor.execute(query_sql) data = cursor.fetchall() # query_sql = "select name, f1, f2 from swap_radas order by f2 desc limit 0,5" # data = exc_sql(query_sql) data = list(data) data = [list(i) for i in data] # df = DataFrame(data, columns=["name", "f1", "f2"]) df = DataFrame(data, columns=["typen", "f1", "f2", "f3", "f4", "f5"]) df[["f1", "f2", "f3", "f4", "f5"]] = df[["f1", "f2", "f3", "f4", "f5"]].astype(float) df = df.sort_values(by='f1', ascending=False) # f1 数量, f2 金额, f2 成功率, f4 最大金额, F5 平均金额 df1 = df['typen'] df2 = df[['f1', 'f2', 'f3', 'f4', 'f5']] # 用于调整雷达各维度的范围大小 c_schema = [{ "name": "数量", "max": df['f1'].max(), "min": -1 }, { "name": "金额", "max": df['f2'].max(), "min": -1 }, { "name": "成功率", "max": df['f3'].max(), "min": -1 }, { "name": "最大金额", "max": df['f4'].max(), "min": -1 }, { "name": "平均金额", "max": df['f5'].max(), "min": -1 }] # # 画图 d1 = [[0.79, 0.90, 0.46, 0.57, -0.50]] # d3 = df2[:1].values.tolist() radar = Radar() radar.config(c_schema=c_schema) # radar.add(df1[1], df2[:1].values.tolist()) # radar.add(df1[2], df2[:2].values.tolist()) # radar.add(df1[3], df2[:3].values.tolist()) # radar.add(df1[4], df2[:4].values.tolist()) # radar.add(df1[5], df2[:5].values.tolist()) radar.add(df1[0:1].values, df2[0:1].values.tolist()) radar.add(df1[1:2], df2[1:2].values.tolist()) radar.add(df1[2:3], df2[2:3].values.tolist()) radar.add(df1[3:4], df2[3:4].values.tolist()) radar.add(df1[4:5], df2[4:5].values.tolist()) # radar.add("数量", [d1]) # radar.add("金额", [d2]) # radar.add("数量", [d1]) context = dict(myechart=radar.render_embed(), host=REMOTE_HOST, script_list=radar.get_js_dependencies()) return HttpResponse(template.render(context, request))
def test_more(): page = Page() # line line = Line("折线图示例") line.add( "最高气温", WEEK, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], ) line.add( "最低气温", WEEK, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], ) # pie v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图-圆环图示例", title_pos="center") pie.add( "", CLOTHES, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient="vertical", legend_pos="left", ) page.add([line, pie]) # kline v1 = [ [2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03], [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07], [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82], [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78], [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22], ] kline = Kline("K 线图示例") kline.add( "日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1, is_datazoom_show=True, ) page.add(kline) # radar schema = [ ("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000), ] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar("雷达图示例") radar.config(schema) radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True) radar.add( "实际开销", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode="single", ) page.add(radar) # scatter3d import random data = [ [ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100), ] for _ in range(80) ] scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600) scatter3D.add("", data, is_visualmap=True, visual_range_color=RANGE_COLOR) page.add(scatter3D) # wordcloud name = [ "Sam S Club", "Macys", "Amy Schumer", "Jurassic World", "Charter Communications", "Chick Fil A", "Planet Fitness", "Pitch Perfect", "Express", "Home", "Johnny Depp", "Lena Dunham", "Lewis Hamilton", "KXAN", "Mary Ellen Mark", "Farrah Abraham", "Rita Ora", "Serena Williams", "NCAA baseball tournament", "Point Break", ] value = [ 10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112, 965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265, ] wordcloud = WordCloud(width=1300, height=620) wordcloud.add("", name, value, word_size_range=[30, 100], rotate_step=66) page.add(wordcloud) # liquid liquid = Liquid("水球图示例") liquid.add("Liquid", [0.6]) page.add(liquid) assert len(page) == 7 assert isinstance(page[0], Line) assert ( ("echarts" in page.js_dependencies) or ("echarts.min" in page.js_dependencies) ) page.render()
def echart03(request): template = loader.get_template('ewpyecharts.html') # 2个系列的5个维度的数据 # value1 = [[0.79, 0.90, 0.46, 0.57, -0.50]] # value2 = [[0.11, 0.34, 0.31, -0.11, 0.21]] d1 = [[0.79, 0.90, 0.46, 0.57, -0.50]] d2 = [[1.11, 0.34, 0.31, -0.11, 0.21]] # sqldata_m = [] # query_sql = "select count(*) 数量, sum(order_m) as 金额, sum(status) 成功率, max(order_m) 最大金额, avg(order_m) 平均金额, typen from myechart_ewsales" # data_list = exc_sql(query_sql) # m=[i[0] for i in data_list] # # query_sql = "select max(f1), max(f2) from swap_radas " # data_list = exc_sql(query_sql) # m1 = data_list[0] # m2 = data_list[1] query_sql = "select name, f1, f2 from swap_radas order by f2 desc limit 0,5" data = exc_sql(query_sql) data = list(data) data = [list(i) for i in data] df = DataFrame(data, columns=["name", "f1", "f2"]) n = list(df["name"]) d1 = list(df["f1"]) d2 = list(df["f2"]) # dd1 = [float(i[1]) for i in data_list] # d1 = list(dd1) # d2 = [i[2] for i in data_list] # query_sql = "select count(*) 数量, sum(order_m) as 金额, sum(status) 成功率, max(order_m) 最大金额, avg(order_m) 平均金额, typen from myechart_ewsales where typen = '营销体系'" # data_list = exc_sql(query_sql) # d2 = [i[0] for i in data_list] # # # 用于调整雷达各维度的范围大小 # c_schema = [{"name": "", "max": 1, "min": -1}, # {"name": "", "max": 1, "min": -1}, # {"name": "", "max": 1, "min": -1}, # {"name": "", "max": 1, "min": -1}, # {"name": "", "max": 1, "min": -1}] # 用于调整雷达各维度的范围大小 c_schema = [{ "name": n[0], "max": 1, "min": -1 }, { "name": n[1], "max": 1, "min": -1 }, { "name": n[2], "max": 1, "min": -1 }, { "name": n[3], "max": 1, "min": -1 }, { "name": n[4], "max": 1, "min": -1 }] # 画图 radar = Radar() radar.config(c_schema=c_schema) radar.add("数量", [d1]) radar.add("金额", [d2]) context = dict(myechart=radar.render_embed(), host=REMOTE_HOST, script_list=radar.get_js_dependencies()) return HttpResponse(template.render(context, request))
def draw_age_radar(data): radar = Radar("妹子年龄分布雷达图") radar.config(age_interval) radar.add("年龄段", data, is_splitline=True, is_axisline_show=True) return radar