from pyecharts import Bar, Line, Scatter, EffectScatter, Grid, Pie
import happybase
import pyecharts
from pyecharts import Bar
conn=happybase.Connection("localhost",9090)
table=conn.table("gdp1")
row=table.row("AnHui_Province")
Anhui_x=[]
Anhui_y=[]
Anhui_x1=[]
for i in range(2000,2015):
Anhui_x.append(i)
Anhui_x1.append(str(i))
a='year:'+str(i)
a=bytes(a,encoding='utf-8')
Anhui_y.append(int(row[a]))
row=table.row("JiangSu_Province")
JS_x=[]
JS_y=[]
JS_x1=[]
for i in range(2000,2015):
JS_x.append(i)
JS_x1.append(str(i))
a='year:'+str(i)
a=bytes(a,encoding='utf-8')
JS_y.append(int(row[a]))
keys=[]
eco=[]
dic={
}
scaner=table.scan()
for k,v in scaner:
row = table.row(k)
a = 'year:2017'
a = bytes(a, encoding='utf-8')
eco.append(int(row[a]))
k=k.decode('utf-8')
keys.append(k)
dic[k]=int(row[a])
key=[]
va=[]
A=sorted(dic.items(),key=lambda dic:dic[1],reverse=True)
j=0
for i in A:
key.append(i[0])
va.append(i[1])
j=j+1
if j>5:
break
year=[]
year_str=[]
all=[]
for i in range(1999, 2018):
year_str.append(str(i))
a = 'year:' + str(i)
year.append(i-1998)
a = bytes(a, encoding='utf-8')
sum=0
scaner = table.scan()
for k,v in scaner:
row = table.row(k)
sum=sum+int(row[a])
all.append(sum)
print(year)
print(all)
'''
Grid类:并行显示多个图表 TODO 第一个图需为 有 x/y 轴的图,即不能为 Pie,其他位置顺序任意。
'''
attr=Anhui_x
v1=Anhui_y
bar = Bar("经济柱状图", title_pos="65%")
bar.add("安徽", attr, v1, is_stack=True)
bar.add("江苏", JS_x, JS_y, is_stack=True, legend_pos="80%")
line = Line("经济折线图")
attr=Anhui_x1
line.add(
"安徽",
attr,
Anhui_y,
mark_point=["max", "min"],
mark_line=["average"],
)
line.add(
"江苏",
JS_x1,
JS_y,
mark_point=["max", "min"],
mark_line=["average"],
legend_pos="20%",
)
v1 = year
v2 = all
scatter = Scatter("全国总经济散点图", title_top="50%", title_pos="65%")
scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%",
)
x = key
y = va
pie = Pie("2017年前六经济饼图",title_top="50%",title_pos="20")
pie.add(
"2017",
x,
y,
radius=[15,35],
center=[25,80],
legend_top="70%",
legend_pos="5%",
legend_orient="vertical",
)
grid = Grid(height=720, width=1200)
grid.add(bar, grid_bottom="60%", grid_left="60%")
grid.add(line, grid_bottom="60%", grid_right="60%")
grid.add(scatter, grid_top="60%", grid_left="60%")
grid.add(pie,grid_top="60%", grid_right="60%")
grid.render("./templates/index.html")