def graph_img(x, y, name): def y_precise(): result = ["chd=t:"] for elem in y: result.append(str(elem)) result.append(',') result[-1] = '&' return ''.join(result) G = Line(y, encoding='text') G.axes.type('xy') min_y = min(y) max_y = max(y) G.axes.range(1, min_y, max_y) G.scale(min_y, max_y) G.axes.label(0, x[0], x[-1]) G.axes.label(1, min_y, max_y) G.title(name) image_code = G.img() norm_img = re.sub(r'chd=t.*?\&', y_precise(), image_code) if len(norm_img) > 2000: if len(image_code) > 2000: raise LongPeriodException() else: return image_code return norm_img
def line_test(): G = Line([[0,10,20], [0,20,25]], encoding='text') #数据 simple模式和text模式 G.size(1000, 200) #整个图的大小 G.axes.type('xy') #XY两轴,可用xyz G.axes.label(0, 30) #设置0(x)轴标签 #G.axes.label(1, '5', '10', '15', '20', '25', '30') #设置1(Y)轴标签 #G.axes.range(0, 0, 5, 1) #设置0(x)轴范围 G.axes.range(1, 0, 50) #设置1(Y)轴范围 G.scale(0, 50) #设置放大比率,最小最大 G.fill('bg', 's', 'e0e0e0') #背景色 G.color('black', 'blue') #两条线的颜色 G.margin(20, 20, 20, 30, 80, 20) #表在图中的位置 G.legend('Merge', 'BigTable') #两标签名字 G.show() #网页显示