Skip to content

Commit

Permalink
echarts增加叠加背景色工具函数
Browse files Browse the repository at this point in the history
  • Loading branch information
yiliuyan161 committed Sep 6, 2023
1 parent 7e9120f commit abb2a85
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
48 changes: 48 additions & 0 deletions chartspy/express/echarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,54 @@ def mark_area_echarts(data_frame: pd.DataFrame, x1: str, y1: str, x2: str, y2: s
return Echarts(options)


def mark_background_echarts(data_frame: pd.DataFrame, x1: str, x2: str, label: str, title: str = 'area',
label_position: str = "top", label_font_size: int = 10, label_distance: int = 10,
label_font_color: str = 'inherit', fill_color: str = "inherit", fill_opacity: float = 0.3
):
"""
在现有图表上叠加背景,不能单独显示
:param data_frame:
:param x1: 左上方顶点x坐标对应列
:param x2: 右下方顶点x坐标对应列
:param label: 矩形标签文字对应列
:param title: 用于在legend显示,控制叠加矩形显示隐藏
:param label_position:top / left / right / bottom / inside / insideLeft / insideRight / insideTop / insideBottom / insideTopLeft / insideBottomLeft / insideTopRight / insideBottomRight
:param label_distance:
:param label_font_size:
:param label_font_color:
:param fill_opacity:
:param fill_color:
:return:
"""
options = copy.deepcopy(ECHARTS_BASE_OVERLAY_OPTIONS)
rows = data_frame[[x1, x2, label]].to_dict(orient='records')
data = [[{'name': row[label], 'xAxis': row[x1]},
{'xAxis': row[x2]}] for row in rows]
base_mark_area_options = {
'itemStyle': {
'opacity': fill_opacity
},
'tooltip': {
'color': "black",
'backgroundColor': "rgba(255,255,255,0.8)"
},
'label': {
'show': True,
'position': label_position,
'distance': label_distance,
'fontSize': label_font_size,
'color': label_font_color
},
'data': data
}
options['series'][0]['name'] = title
options['series'][0]['markArea'] = base_mark_area_options
options['legend']['data'] = [title]
return Echarts(options)



def mark_segment_echarts(data_frame: pd.DataFrame, x1: str, y1: str, x2: str, y2: str, label: str, title="segment",
show_label: bool = False,
label_position: str = "middle", label_font_size: int = 10, label_distance: int = 10,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_install_requires():

setup(
name="chartspy",
version="2.1.1",
version="2.1.2",
url="https://chartspy.icopy.site/",
description="echarts g2plot klinechart highcharts tabulator python wrapper",
keywords='echarts g2plot klinechart highcharts tabulator python ',
Expand Down

0 comments on commit abb2a85

Please sign in to comment.