因为需要,所以HIGHCHARTS了解一下是很有必要的。
但原始应用确实效率不行。
刚好,现在有个需求是从一系列的JSON里抽出表格数据,再显示图形。
jquery.highchartsTable.js怕个是极好的了。。 基本文档URL: http://www.hcharts.cn/p/highchartTable.php
代码,
#!/usr/bin/python#coding:utf-8import datetimeimport jsonimport sysstr_today = datetime.datetime.now().strftime('-%Y-%m-%d')func_dict = { "103":("查","恒"), }html_header = '''HighCharts '''html_footer = ''' ''''''with open('measurements.json', 'w') as f: f.write(json.dumps(str_json,ensure_ascii=False,indent=2))'''# 将字典排序def sort_dict(dict_item): sort_dict_item = sorted(dict_item.iteritems(),key=lambda t:t[0],reverse=False) return sort_dict_item def gen_content(): json_file = "json/data" + str_today + ".json" with open(json_file) as f: data = f.read() # print data json_data = json.loads(data) dict_len = len(json_data) sort_json_data = sort_dict(json_data) return sort_json_datadef zip_pkg(): passdef send_mail(): passdef gen_html(): html_filename = "index" + str_today + ".html" html_content = '' content_dict = gen_content() # 带循环次数,方便定位container for i, item_number in enumerate(content_dict): html_content += ''' 趋势数据展示页面" # print html_content html_total = html_header + html_content + html_footer with open(html_filename, 'w') as f: f.write(html_total) def main(): gen_html() zip_pkg() send_mail()if __name__ == '__main__': main() print 'finished!'
{title} '''.format(c_number = i+1, title=item_number[1][0]['title'].encode('utf-8')) # 定位各个数据结构 for i, item_head in enumerate(item_number[1][1]['head']): if i == 0: html_content += ''' ' for item_content in item_number[1][2]['content']: html_content += '{item_head} '''.format(item_head=item_head.encode('utf-8')) else: # 此处预留显示系统功能字段 # html_content += '''{item_func}{item_code}|{item_sys} '''.format( # item_func=func_dict[item_head][0],item_code=item_head,item_sys=func_dict[item_head][1]) html_content += '''{item_func}{item_code} '''.format( item_func=func_dict[item_head][0], item_code=item_head) html_content += '' for item_end in item_content: if isinstance(item_end,(int,float)): html_content += ''' ' html_content += "{item_end} '''.format(item_end=item_end) else: html_content += '''{item_end} '''.format(item_end=item_end.encode('utf-8')) pass html_content += '
HTML生成的东东: