ITeye博客

python : pyecharts K线图

belldeep · 2019-02-10 18:51 · python · 编程语言 · Markdown

官方中文版帮助文档 http://pyecharts.org/#/zh-cn/ Kline/Candlestick(K线图) 红涨蓝跌 Kline.add() 方法签名 add(name, x_axis, y_axis, **kwargs) name -> str 图例名称 x_axis -> list x 坐标轴数据 y_axis -> , 包含列表的列表 y 坐标轴数据。数据中,每一行是一个『数据项』,每一列属于一个『维度』。 数据项: (即:) 实例: kline1.py


import os, sys
from pyecharts import Kline

if len(sys.argv) ==2:
    fcode = sys.argv[1]
else:
    print('usage: kline1.py fcode ')
    sys.exit(1)

if len(fcode) !=6:
	print(' fcode is char(6)')
	sys.exit(2)

file1 = 'M'+fcode +'.csv'
file2 = 'M'+fcode +'.html'

if not os.path.exists(file1):
	print(file1 +' is not exists.')
	sys.exit(3)

# 数据项: [open, close, lowest, highest] (即:[开盘值, 收盘值, 最低值, 最高值])
alist = []
vlist = []
fp = open(file1,'r')
fp.readline() # 跳过第1行表头: ym,open,close,low,high
for line in fp:
	ym,open,close,low,high = line.strip().split(',')
	alist.append(ym)
	vlist.append([open,close,low,high])
print(str(len(alist)))
kline = Kline(fcode+" 月K线图")
kline.add(fcode, alist, vlist)
kline.render(path=file2)

参考 https://blog.csdn.net/qtlyx/article/details/85221503

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。