This commit is contained in:
chenjiandongx 2018-07-19 21:56:30 +08:00
commit 528ff57ad6
14 changed files with 299 additions and 116 deletions

View File

@ -118,6 +118,8 @@ pyecharts exposes chart API and template API so that it can work on other python
### Integration with Jupyter Notebook/nteract
#### Notebook
In the Notebook cell, you can simply pass on chart instance itself to Jupyter, which will diplay the chart. Please note **render_notebook** function has been removed.
All chart classes in pyecharts implement the `_repr_html_` interface about [IPython Rich Display](http://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display) .
@ -130,12 +132,14 @@ In the case of online jshost mode, you can also download as some file formats (i
Since pyecharts 0.5.5+, [nteract](https://nteract.io) is supported. Once the following two lines should added to your notebook, you could use pyecharts in nteract in the same way as in jupyter notebook.
```
```python
from pyecharts import enable_nteract
enable_nteract()
```
![](https://user-images.githubusercontent.com/19553554/40266807-2c3ddcc2-5b84-11e8-8240-d3398243d4a6.png)
However, when rendering output as image, the instructions are the same as jupyter notebook. Only default html(including js) output should call `enable_nteract()`.
### Integrate With Web Framework

View File

@ -7,7 +7,7 @@ pyecharts 是一个用于生成 Echarts 图表的类库。Echarts 是百度开
**基本使用**
[渲染图表](zh-cn/prepare) | [图表配置](zh-cn/charts)
[渲染图表](zh-cn/prepare) | [图表配置](zh-cn/charts) | [数据解析与导入](zh-cn/data_import)
**高级话题**
@ -23,7 +23,7 @@ pyecharts 是一个用于生成 Echarts 图表的类库。Echarts 是百度开
**项目发布**
[版本日志](zh-cn/changelog) | [发布日志](zh-cn/release-note/)
[版本日志](zh-cn/changelog) | [里程碑](zh-cn/release-note/)
**项目开发**

View File

@ -307,25 +307,6 @@ v0.5.4 新增,可链式使用。添加一个图表对象,如果如果没有
这些方法的使用方法同 `Base` 类。
## 数据处理工具
以下几个方法为数据处理的类方法,
**cast**
`pyecharts.base.Base.cast(seq)`
数据格式化处理函数,能够将源数据转化为符合 pyecharts 的数据。
例子:
```python
o_data = [('A', '34'), ('B', '45'), ('C', '12')]
x, y = Base.cast(o_data)
print(x) # ['A', 'B', 'C']
print(y) # ['34', '45', '12']
```
## 模板引擎
### 概述

View File

@ -1,8 +1,12 @@
# 版本日志
* ### version 0.5.6dev
#### Fixed
* [issue#452](https://github.com/pyecharts/pyecharts/issues/452) 修复 K 线图显示提示的【open, close, lowest, highest】
* [issue#452](https://github.com/pyecharts/pyecharts/issues/452) 修复 K 线图不能显示 tooltip【open, close, lowest, highest】的 bug
#### Updated
* 修正参数拼写,将 `tooltip_tragger`, `tooltip_tragger_on` 修正为 `tooltip_trigger`, `tooltip_trigger_on`
* ### version 0.5.5 - 2018.05.17current
@ -78,7 +82,7 @@
* 修正 width / height 在 Jupyter Notebook 渲染错误的 Bug
* [issue#432](https://github.com/pyecharts/pyecharts/issues/432) 修复水球图和词云图不能指定 Toolbox 等选项的 Bug
* ### version 0.3.3 - 2018.03.01Current
* ### version 0.3.3 - 2018.03.01
#### Added
* 防止将来的依赖包影响 v0.3.2 的功能: lml==0.0.2, jupyter-echarts-pypkg==0.0.11

View File

@ -442,12 +442,12 @@
**tooltip提示框组件用于移动或点击鼠标时弹出数据内容**
* tooltip_tragger -> str
* tooltip_trigger -> str
触发类型。默认为 'item'
* 'item': 数据项图形触发,主要在散点图,饼图等无类目轴的图表中使用。
* 'axis': 坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用。
* 'none': 什么都不触发。
* tooltip_tragger_on -> str
* tooltip_trigger_on -> str
提示框触发的条件。默认为 "mousemove|click"
* 'mousemove': 鼠标移动时触发。
* 'click': 鼠标点击时触发。

138
docs/zh-cn/data_import.md Normal file
View File

@ -0,0 +1,138 @@
> 数据解析与导入篇:介绍了一些常用的数据处理模块和库。这些并不是 pyecharts 核心的部分。
## numpy 数据类型
add 数据直接支持 `numpy.array` 对象,例如:
```python
from pyecharts import Bar
import numpy as np
clothes = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = np.array([5, 20, 36, 10, 75, 90])
bar = Bar("衣服销量")
bar.add("商家A", clothes, v1, is_stack=True)
bar.render()
```
## zip 函数
`pyecharts.base.Base.add(name, x_axis, y_axis)` 函数中,数据参数通常要求数据是两个长度相等的列表。
```python
from pyecharts import Line
t_data = [(21, '2017-12-01'), (19, '2017-12-02'), (20, '2017-12-03')]
hs, ds = zip(*t_data)
line = Line('High Temperature')
line.add('High', ds, hs)
line.render()
```
## Base.cast 函数
数据格式化处理函数,能够将源数据转化为符合 pyecharts 的数据。
```python
o_data = [('A', '34'), ('B', '45'), ('C', '12')]
x, y = Base.cast(o_data)
print(x) # ['A', 'B', 'C']
print(y) # ['34', '45', '12']
```
上述例子也可以直接使用 `zip` 函数。
## borax.fetch 模块
> 项目地址: https://github.com/kinegratii/borax
### 安装
borax 要求 Python3.5 以上,可以使用以下命令安装这个库。
```shell
$ pip install borax
```
### 函数定义文档
该模块使用 `fetch` 函数,签名如下:
```python
fetch(iterable, key, *keys, default=EMPTY, defaults=None, getter=None)
```
各参数的意义如下:
- iterable数据列表
- key / keys键值、属性访问方式的索引
- default默认值用于选择单个属性
- defaults默认值字典用于选择多个属性
- getter自定义访问回调函数
应当注意的是,在使用时, *default**defaults**getter* 参数必须使用关键字方式传递,详情参考 [PEP 3102](https://www.python.org/dev/peps/pep-3102/)。
### 示例
选取多个属性
```python
from borax.fetch import fetch
objects = [
{'id': 282, 'name': 'Alice', 'age': 30},
{'id': 217, 'name': 'Bob', 'age': 56},
{'id': 328, 'name': 'Charlie', 'age': 56},
]
names, ages = fetch(objects, 'name', 'age')
print(names)
print(ages)
```
输出
```
['Alice', 'Bob', 'Charlie']
[30, 56, 56]
```
## networkx 库
> 项目地址: https://github.com/networkx/networkx
对于复杂的关系图,可以使用 [networkx](https://github.com/networkx/networkx) 库构建节点和连线,并传递给 add 函数。如下面的例子。
```python
# coding=utf8
from __future__ import unicode_literals
import networkx as nx
from networkx.readwrite import json_graph
from pyecharts import Graph
g = nx.Graph()
categories = ['网关', '节点']
g.add_node('FF12C904', name='Gateway 1', symbolSize=40, category=0)
g.add_node('FF12CA02', name='Node 11', category=1)
g.add_node('FF12C326', name='Node 12', category=1)
g.add_node('FF45C023', name='Node 111', category=1)
g.add_node('FF230933', name='Node 1111', category=1)
g.add_edge('FF12C904', 'FF12CA02')
g.add_edge('FF12C904', 'FF12C326')
g.add_edge('FF12CA02', 'FF45C023')
g.add_edge('FF45C023', 'FF230933')
g_data = json_graph.node_link_data(g)
eg = Graph('设备最新拓扑图')
eg.add('Devices', nodes=g_data['nodes'], links=g_data['links'], categories=categories)
# eg.show_config()
eg.render()
```
结果
![networkx-demo](http://django-echarts.readthedocs.io/zh_CN/latest/_images/networkx-graph-demo.png)

View File

@ -1,5 +1,29 @@
# 版本日志
## 开发里程碑
- [v0.5.0](zh-cn/release-note/v050)
- [v0.3.2](zh-cn/release-note/v032)
- [v0.3.0](zh-cn/release-note/v030)
- v0.5.5 - 2018.05.17
- 支持 [nteract](https://nteract.io/) 平台
- v0.5.0 - 2018.04.28[发布日志](zh-cn/release-note/v050)
- 支持 JavaScript 回调函数配置项和事件绑定
- v0.4.0 - 2018.03.09
- 更新至 ECharts 4
- v0.3.2 - 2018.02.26 [发布日志](zh-cn/release-note/v032)
- 独立发布地图数据库 echarts-maps
- v0.3.0 - 2017.12.11 [发布日志](zh-cn/release-note/v030)
- 新增自定义模板支持
- v0.2.7 - 2017.10.27
- 全面支持28个图表类型
- v0.1.9.3 - 2017.8.10
- 支持 Django / Flask
- v0.1.9.2 - 2017.8.6
- 支持 Jupyter Notebook
- v0.1.4 - 2017.7.20
- 第一个稳定版本

View File

@ -257,8 +257,8 @@ class Chart(Base):
sankey_node_width=None,
sankey_node_gap=None,
type=None,
tooltip_tragger=None,
tooltip_tragger_on=None,
tooltip_trigger=None,
tooltip_trigger_on=None,
tooltip_axispointer_type=None,
tooltip_formatter=None,
tooltip_text_color=None,

View File

@ -32,6 +32,8 @@ class Gauge(Chart):
:param kwargs:
"""
kwargs.update(type="gauge")
if "tooltip_formatter" not in kwargs:
kwargs["tooltip_formatter"] = "{a} <br/>{b} : {c}%"
_min, _max = 0, 100
if scale_range:
if len(scale_range) == 2:

View File

@ -92,11 +92,13 @@ class Geo(Chart):
"""
assert len(attr) == len(value)
kwargs.update(type="geo")
if "tooltip_formatter" not in kwargs:
kwargs["tooltip_formatter"] = "{b}: {c}"
chart = self._get_all_options(**kwargs)
if geo_cities_coords:
for name, coord in geo_cities_coords.items():
self.add_coordinate(name, coord[0], coord[1])
for city_name, city_coord in geo_cities_coords.items():
self.add_coordinate(city_name, city_coord[0], city_coord[1])
_data = []
for _name, _value in zip(attr, value):

View File

@ -49,6 +49,10 @@ class Kline(Chart):
:param kwargs:
"""
kwargs.update(type="candlestick", x_axis=x_axis)
if "tooltip_formatter" not in kwargs:
kwargs["tooltip_formatter"] = kline_tooltip_formatter
if "tooltip_trigger" not in kwargs:
kwargs["tooltip_trigger"] = "axis"
chart = self._get_all_options(**kwargs)
xaxis, yaxis = chart["xy_axis"]
@ -70,6 +74,3 @@ class Kline(Chart):
}
)
self._config_components(**kwargs)
self._option["tooltip"]["trigger"] = "axis"
if self._option["tooltip"]["formatter"] is None:
self._option["tooltip"]["formatter"] = kline_tooltip_formatter

View File

@ -2,3 +2,4 @@
from .label import NormalLabel, EmphasisLabel
from .line import Line
from .axis import XAxisLabel, YAxisLabel, XAxis, YAxis
from .tooltip import Tooltip

View File

@ -1135,85 +1135,8 @@ def zaxis3D(
@collectfuncs
def tooltip(
type=None,
tooltip_tragger="item",
tooltip_tragger_on="mousemove|click",
tooltip_axispointer_type="line",
tooltip_formatter=None,
tooltip_text_color=None,
tooltip_font_size=14,
tooltip_background_color="rgba(50,50,50,0.7)",
tooltip_border_color="#333",
tooltip_border_width=0,
**kwargs
):
"""
提示框组件用于移动或点击鼠标时弹出数据内容
:param type:
图形类型
:param tooltip_tragger:
触发类型默认为 'item'
'item': 数据项图形触发主要在散点图饼图等无类目轴的图表中使用
'axis': 坐标轴触发主要在柱状图折线图等会使用类目轴的图表中使用
'none': 什么都不触发
:param tooltip_tragger_on:
提示框触发的条件默认为 "mousemove|click"
'mousemove': 鼠标移动时触发
'click': 鼠标点击时触发
'mousemove|click': 同时鼠标移动和点击时触发
'none': 不在 'mousemove' 'click' 时触发
:param tooltip_axispointer_type:
指示器类型默认为 "line"
'line': 直线指示器
'shadow': 阴影指示器
'cross': 十字准星指示器其实是种简写表示启用两个正交的轴的 axisPointer
:param tooltip_formatter:
模板变量有 {a}, {b}{c}{d}{e}分别表示系列名数据名数据值等
使用示例 label_formatter='{a}'
trigger 'axis' 的时候会有多个系列的数据此时可以通过 {a0}, {a1}, {a2}
这种后面加索引的方式表示系列的索引不同图表类型下的 {a}{b}{c}{d} 含义不一样
其中变量 {a}, {b}, {c}, {d} 在不同图表类型下代表数据含义为
折线区域柱状条形K线图 :
{a}系列名称{b}类目值{c}数值, {d}
散点图气泡 :
{a}系列名称{b}数据名称{c}数值数组, {d}
地图 :
{a}系列名称{b}区域名称{c}合并数值, {d}
饼图仪表盘漏斗图:
{a}系列名称{b}数据项名称{c}数值, {d}百分比
:param tooltip_text_color:
提示框字体颜色默认为 '#fff'
:param tooltip_font_size:
提示框字体大小默认为 14
:param tooltip_background_color:
提示框浮层的背景颜色默认为 "rgba(50,50,50,0.7)"
:param tooltip_border_color:
提示框浮层的边框颜色默认为 "#333"
:param tooltip_border_width:
提示框浮层的边框宽默认为 0
"""
_tmp_formatter = tooltip_formatter
if tooltip_formatter is None:
if type == "gauge":
_tmp_formatter = "{a} <br/>{b} : {c}%"
elif type == "geo":
_tmp_formatter = "{b}: {c}"
_tooltip = {
"trigger": tooltip_tragger,
"triggerOn": tooltip_tragger_on,
"axisPointer": {"type": tooltip_axispointer_type},
"formatter": _tmp_formatter,
"textStyle": {
"color": tooltip_text_color, "fontSize": tooltip_font_size
},
"backgroundColor": tooltip_background_color,
"borderColor": tooltip_border_color,
"borderWidth": tooltip_border_width,
}
return _tooltip
def tooltip(**kwargs):
return option.Tooltip(**kwargs)
@collectfuncs

View File

@ -0,0 +1,103 @@
# coding=utf-8
from pyecharts.echarts.json_serializable import JsonSerializable
class Tooltip(JsonSerializable):
def __init__(
self,
tooltip_trigger="item",
tooltip_trigger_on="mousemove|click",
tooltip_axispointer_type="line",
tooltip_formatter=None,
tooltip_text_color=None,
tooltip_font_size=14,
tooltip_background_color="rgba(50,50,50,0.7)",
tooltip_border_color="#333",
tooltip_border_width=0,
**kwargs
):
"""
提示框组件用于移动或点击鼠标时弹出数据内容
:param tooltip_trigger:
触发类型默认为 'item'
'item': 数据项图形触发主要在散点图饼图等无类目轴的图表中使用
'axis': 坐标轴触发主要在柱状图折线图等会使用类目轴的图表中使用
'none': 什么都不触发
:param tooltip_trigger_on:
提示框触发的条件默认为 "mousemove|click"
'mousemove': 鼠标移动时触发
'click': 鼠标点击时触发
'mousemove|click': 同时鼠标移动和点击时触发
'none': 不在 'mousemove' 'click' 时触发
:param tooltip_axispointer_type:
指示器类型默认为 "line"
'line': 直线指示器
'shadow': 阴影指示器
'cross': 十字准星指示器其实是种简写表示启用两个正交的轴的 axisPointer
:param tooltip_formatter:
模板变量有 {a}, {b}{c}{d}{e}分别表示系列名数据名数据值等
使用示例 label_formatter='{a}'
trigger 'axis' 的时候会有多个系列的数据此时可以通过 {a0}, {a1}, {a2}
这种后面加索引的方式表示系列的索引不同图表类型下的 {a}{b}{c}{d} 含义不一样
其中变量 {a}, {b}, {c}, {d} 在不同图表类型下代表数据含义为
折线区域柱状条形K线图 :
{a}系列名称{b}类目值{c}数值, {d}
散点图气泡 :
{a}系列名称{b}数据名称{c}数值数组, {d}
地图 :
{a}系列名称{b}区域名称{c}合并数值, {d}
饼图仪表盘漏斗图:
{a}系列名称{b}数据项名称{c}数值, {d}百分比
yaxis_formatter -> function
def tooltip_formatter(params):
return params.value + ' [Good!]'
回调函数格式更多内容请参考 [高级用法篇](zh-cn/advanced)
```
(params: Object|Array) => string
参数 params formatter 需要的单个数据集格式如下
{
componentType: 'series',
// 系列类型
seriesType: string,
// 系列在传入的 option.series 中的 index
seriesIndex: number,
// 系列名称
seriesName: string,
// 数据名类目名
name: string,
// 数据在传入的 data 数组中的 index
dataIndex: number,
// 传入的原始数据项
data: Object,
// 传入的数据值
value: number|Array,
// 数据图形的颜色
color: string,
}
:param tooltip_text_color:
提示框字体颜色默认为 '#fff'
:param tooltip_font_size:
提示框字体大小默认为 14
:param tooltip_background_color:
提示框浮层的背景颜色默认为 "rgba(50,50,50,0.7)"
:param tooltip_border_color:
提示框浮层的边框颜色默认为 "#333"
:param tooltip_border_width:
提示框浮层的边框宽默认为 0
"""
self._config = {
"trigger": tooltip_trigger,
"triggerOn": tooltip_trigger_on,
"axisPointer": {"type": tooltip_axispointer_type},
"formatter": tooltip_formatter,
"textStyle": {
"color": tooltip_text_color, "fontSize": tooltip_font_size
},
"backgroundColor": tooltip_background_color,
"borderColor": tooltip_border_color,
"borderWidth": tooltip_border_width,
}