BigCharts 图表
由jliang创建,最终由ydong 被浏览 327 用户
接口
- 使用 bigcharts.Chart 构架一个图表对象
- 调用 render 函数渲染输出
import bigcharts
bigcharts.Chart(...).render(...)
定义
bigcharts.Chart
bigcharts.Chart(
# 图表数据,如果是str,表示是一个dai数据查询,会调用 dai.query 获取数据
data: Optional[DATA_TYPE],
# 【设置图表类型】图表类型,具体参考各类型图表
type_: CHART_TYPE = "line",
# x轴数据列名
x: Optional[str] = None,
# y轴数据列名,列表
y: Optional[List[str]] = None,
# 图表全局定义,配置项见如下 CHART_OPTIONS_KEYS,可以参考 pyecharts 的全局配置 (set_global_opts)
chart_options: Dict[CHART_OPTIONS_KEYS, Any] = {},
# 【不同图表类型定义不同】各数据系列配置项,其中key为数据系列名称,value为配置项,配置项定义见具体图表
# 如果 key="*",其配置项value会应用到所有数据列
series_options: COLUMNS_SERIES_OPTIONS = {},
# 初始配置项,定义见如下 bigcharts.opts.InitOpts
init_opts: Optional[bigcharts.opts.InitOpts] = None,
# shortcut for init_opts
# 页面高度,如果是整数,表示 px
height: Optional[Union[int, str]] = None,
# 页面宽度,如果是整数,表示 px
width: Optional[Union[int, str]] = "100%",
# 页面标题
page_title: str = "BigCharts",
# 主题样式,见bigcharts.ThemeType bigcharts.ThemeType
theme: str = ThemeType.WHITE,
# shortcut for title_opts
# 图表标题
title: str = "",
# 副标题
subtitle: str = "",
) -> bigcharts.Chart
不同图表主要是 type_ 和 series_options 值不一样。
接口用到的类型定义
# 如果是 str,则会调用 dai.query 获取数据
DATA_TYPE = TypeVar("DATA_TYPE", pd.DataFrame, pa.Table, BigDBPyRelation, QueryResult, str)
CHART_TYPE = Literal["bar", "boxplot", "effectscatter", "kline", "line", "pictorialbar", "scatter", "wordcloud"]
# { 列: 列对应的所有options }
COLUMNS_SERIES_OPTIONS = Dict[str, Dict[str, Any]]
# 具体定义见对应配置项目
# 例如: toolbox_opts 对应配置项为 bigcharts.opts.TitleOpts
# 查看文档:help(bigcharts.opts.TitleOpts)
CHART_OPTIONS_KEYS = Literal[
"title_opts",
"legend_opts",
"tooltip_opts",
"toolbox_opts",
"brush_opts",
"xaxis_opts",
"yaxis_opts",
"visualmap_opts",
"datazoom_opts",
"graphic_opts",
"axispointer_opts",
# 扩展更多x轴,数组,每个元素是一个x轴定义,两个元素的tuple: [(data_column_name: str, xaxis: types.Axis)]
"extend_xaxis",
# 扩展更多y轴,数组,每个元素是一个y轴定义: [yaxis: types.Axis]
"extend_yaxis",
# 交换x/y轴,e.g. 反转bar的方向
"reversal_axis",
]
DEFAULT_X_COLUMN = "date"
bigcharts.opts.InitOpts(
width: str = "900px",
height: str = "500px",
is_horizontal_center: bool = False,
chart_id: Optional[str] = None,
renderer: str = bigcharts.RenderType.CANVAS,
page_title: str = "BigCharts",
theme: str = bigcharts.ThemeType.WHITE,
bg_color: Union[str, dict] = None,
is_fill_bg_color: bool = False,
js_host: str = "",
animation_opts: Union[AnimationOpts, dict] = AnimationOpts(),
aria_opts: Union[AriaOpts, dict] = AriaOpts(),
)
# 主题样式
bigcharts.ThemeType:
# BUILTIN_THEMES = ["light", "dark", "white"]
LIGHT = "light"
DARK = "dark"
WHITE = "white"
CHALK: str = "chalk"
ESSOS: str = "essos"
INFOGRAPHIC: str = "infographic"
MACARONS: str = "macarons"
PURPLE_PASSION: str = "purple-passion"
ROMA: str = "roma"
ROMANTIC: str = "romantic"
SHINE: str = "shine"
VINTAGE: str = "vintage"
WALDEN: str = "walden"
WESTEROS: str = "westeros"
WONDERLAND: str = "wonderland"
HALLOWEEN: str = "halloween"
.render
bigcharts.Chart(..).render(
# 压缩输出的内容,提高加载速度
minify: bool = True,
# 直接显示图表,如果为 False,则返回 HTML
display: bool = True,
) -> Optional[HTML]
\