• simple2.py


     1 #coding: utf-8
     2 import xlsxwriter
     3 
     4 workbook = xlsxwriter.Workbook('chart.xlsx')
     5 worksheet = workbook.add_worksheet()
     6 
     7 chart = workbook.add_chart({'type': 'column'})
     8 
     9 title = [u'业务名称',u'星期一',u'星期二',u'星期三',u'星期四',u'星期五',u'星期六',u'星期日',u'平均流量']
    10 buname= [u'业务官网',u'新闻中心',u'购物频道',u'体育频道',u'亲子频道']
    11 
    12 data = [
    13     [150,152,158,149,155,145,148],
    14     [89,88,95,93,98,100,99],
    15     [201,200,198,175,170,198,195],
    16     [75,77,78,78,74,70,79],
    17     [88,85,87,90,93,88,84],
    18 ]
    19 format=workbook.add_format()
    20 format.set_border(1)
    21 
    22 format_title=workbook.add_format()
    23 format_title.set_border(1)
    24 format_title.set_bg_color('#cccccc')
    25 format_title.set_align('center')
    26 format_title.set_bold()
    27 
    28 format_ave=workbook.add_format()
    29 format_ave.set_border(1)
    30 format_ave.set_num_format('0.00')
    31 
    32 worksheet.write_row('A1',title,format_title)
    33 worksheet.write_column('A2', buname,format)
    34 worksheet.write_row('B2', data[0],format)
    35 worksheet.write_row('B3', data[1],format)
    36 worksheet.write_row('B4', data[2],format)
    37 worksheet.write_row('B5', data[3],format)
    38 worksheet.write_row('B6', data[4],format)
    39 
    40 def chart_series(cur_row):
    41     worksheet.write_formula('I'+cur_row, 
    42      '=AVERAGE(B'+cur_row+':H'+cur_row+')',format_ave)
    43     chart.add_series({
    44         'categories': '=Sheet1!$B$1:$H$1',
    45         'values':     '=Sheet1!$B$'+cur_row+':$H$'+cur_row,
    46         'line':       {'color': 'black'},
    47         'name':    '=Sheet1!$A$'+cur_row,
    48     })
    49 
    50 for row in range(2, 7):
    51     chart_series(str(row))
    52 
    53 #chart.set_table()
    54 #chart.set_style(30)
    55 chart.set_size({'width': 577, 'height': 287})
    56 chart.set_title ({'name': u'业务流量周报图表'})
    57 chart.set_y_axis({'name': 'Mb/s'})
    58 
    59 worksheet.insert_chart('A8', chart)
    60 workbook.close()
  • 相关阅读:
    ESRI系列产品报价表(ArcGIS 9.2系列)
    如何将区域插入到表中【转载】
    MapInfo注记的数据库存放解决方案
    最短路径问题的算法实现【转载】
    Web Services
    MapX从数据库读取数据形成新图层【转载】
    Hessian连接超时设置
    MINA学习
    Hessian解析及应用(整合Spring)
    Ant使用
  • 原文地址:https://www.cnblogs.com/catgatp/p/7875603.html
Copyright © 2020-2023  润新知