charts库实际是对调用Highcharts API 进行封装,通过python生成Highcharts脚本
Highcharts中文网:http://v1.hcharts.cn/demo/index.php?p=10
Highcharts官网:http://api.highcharts.com/highcharts/title
http://nbviewer.jupyter.org/github/arnoutaertgeerts/python-highcharts/blob/master/Tutorial.ipynb#Data-configuration
中文API文档
https://api.hcharts.cn/highcharts
1.安装
import charts Server running in the folder /Users/TiM/PycharmProjects/58 at 127.0.0.1:61664 这个目录是你当前目录 如果报错,则需要 import sys print(sys.path) 找到类似下面的路径 '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages' 然后进入目录下的chart目录,拷贝下图这些文件替换
1.If you want to plot a single series, you can use the name argument:
charts.plot(data, name='My list')
2.If you want to plot multiple series, you have to use the series format. This format is a dictionary containing two properties: data and name:
charts.plot(dict(data=data, name='My series'))
The data itself has to be one of these two options:
可以再serie中指定color颜色,type显示的形式(column:柱状图,bar:横向柱状图,line:曲线,area:范围,spline:曲线,scatter:点状,pie:饼状图)
series = [{ 'type': 'pie', 'name': 'Browser share', 'data': [ ['Firefox', 45.0], ['IE', 26.8], { 'name': 'Chrome', 'y': 12.8, 'sliced': True,#控制是否脱离整个pie 'selected': True #http://api.highcharts.com/highcharts/plotOptions.pie }, ['Safari', 8.5], ['Opera', 6.2], ['Others', 0.7] ] }] charts.plot(series, options={'title': {'text': 'A pie chart'}}, show='inline')
在一个例子
series = [ { 'name': 'OS X', 'data': [11,2,3,4], 'type': 'line', 'y':5 }, { 'name': 'Ubuntu', 'data': [8,5,6,7], 'type': 'line', 'color':'#ff0066' }, { 'name': 'Windows', 'data': [12,6,7,2], 'type': 'line' }, { 'name': 'Others', 'data': [29,24,68,23], 'type': 'line' } ] options = { 'chart' : {'zoomType':'xy'}, 'title' : {'text': 'Monthly Average Temperature'}, 'subtitle': {'text': 'Source: WorldClimate.com'}, 'xAxis' : {'categories': ['周一', '周二', '周三', '周四']}, 'yAxis' : {'title': {'text': '数量'}} } charts.plot(series, options=options,show='inline')
http://api.highcharts.com/highcharts/plotOptions
series = [{ 'name': 'John', 'data': [5, 3, 4, 7, 2] }, { 'name': 'Jane', 'data': [2, -2, -3, 2, 1] }, { 'name': 'Joe', 'data': [3, 4, 4, -2, 5] }] #options = dict(title=dict(text='Area chart')) options = { 'title': {'text': 'A chart with two lines, wow!'}, #图标的标题 'height':400, #整个图标的高度 'chart':{'zoomType':'xy'}, #zoom是缩放,可以是 x,y或 xy 'plotOptions': { 'spline': { #这个area是你的type 'dataLabels': {'enabled': True, 'shadow':True, 'backgroundColor': 'rgba(252, 255, 197, 0.7)',#lable颜色,这里是淡黄色 'borderRadius': 10, #圆角,默认是0,lable是方的,这里10已经比较园了 'borderWidth': 1,#不清楚 'padding': 5, #When either the borderWidth or #the backgroundColor is set, this is the padding within the box #反正就是变大了 'style': {'fontWeight': 'bold'} } #在图上直接显示数值,lable } } } charts.plot(series, options=options, show='inline', type='spline')