import xlrd from pyecharts.charts import Line {from datetime import date import pyecharts.options as opts import webbrowser # 用于自动打开生成的HTML文件 data = xlrd.open_workbook(r'C:\Users\11724\Desktop\原始行情数据.xlsx') table = data.sheet_by_index(0) dt_dates = [] #日期 dt_sps = [] #收盘价 for i in range(1,table.nrows-2): dt_date = table.row_values(i)[2] dt_date = xlrd.xldate_as_tuple(dt_date, data.datemode) dt_date = date(*dt_date[:3]) dt_dates.append(dt_date) dt_sp = table.row_values(i)[6] dt_sps.append(dt_sp) line = Line(init_opts=opts.InitOpts(width='1200px',height='700px')) line.add_xaxis(dt_dates) line.add_yaxis('收盘价', dt_sps) # 设置标题等 line.set_global_opts(title_opts=opts.TitleOpts('茅台股价变化')) line.render('茅台股价变化.html') webbrowser.open('茅台股价变化.html')