fix Overlap and Grid can't be used together partically

This commit is contained in:
chenjiandongx 2017-09-26 20:00:09 +08:00
parent 220e432448
commit f540dfb49a
4 changed files with 46 additions and 18 deletions

View File

@ -56,19 +56,19 @@ class Grid(object):
chart._option.get('legend')[0],
chart._option.get('title')[0]
)
_index, _index_once, _xaxis, _yaxis, _legned, _title = self.__custom(_series)
self._chart._option.get('legend').append(_legned)
_index, _index_once, _xaxis, _yaxis, _legend, _title = self.__custom(_series)
self._chart._option.get('legend').append(_legend)
self._chart._option.get('title').append(_title)
if _xaxis and _yaxis is not None:
try:
_xaxis[0].update(gridIndex=_index-1)
_yaxis[0].update(gridIndex=_index-1)
self._chart._option.get('xAxis').append(_xaxis[0])
self._chart._option.get('yAxis').append(_yaxis[0])
except:
pass
# indexflag is the only identify for every series
if _xaxis and _yaxis is not None:
for _x in _xaxis:
_x.update(gridIndex=_index - 1)
self._chart._option.get('xAxis').append(_x)
for _y in _yaxis:
_y.update(gridIndex=_index - 1)
self._chart._option.get('yAxis').append(_y)
# series id is the only identify for every series
_flag = self._chart._option.get('series')[0].get('seriesId')
_series_index = 0
for s in self._chart._option.get('series'):

View File

@ -12,7 +12,11 @@ class Overlap(object):
self._js_dependencies = set()
self._page_title = page_title
def add(self, chart, xaxis_index=0, yaxis_index=0, is_add_xaxis=False, is_add_yaxis=False):
def add(self, chart,
xaxis_index=0,
yaxis_index=0,
is_add_xaxis=False,
is_add_yaxis=False):
"""
:param chart:
@ -29,6 +33,7 @@ class Overlap(object):
"""
if self._chart is None:
self._chart = chart
self._series_id = chart._option.get('series')[0].get('seriesId')
self._js_dependencies = chart._js_dependencies
else:
_series = (
@ -43,6 +48,7 @@ class Overlap(object):
)
self.__custom(_series)
self._js_dependencies = self._js_dependencies.union(chart._js_dependencies)
self._option = self._chart._option
def __custom(self, series):
""" Appends the data for the series of the chart type
@ -55,7 +61,8 @@ class Overlap(object):
for n in _name:
self._chart._option.get('legend')[0].get('data').append(n)
for s in _series:
s.update(xAxisIndex=_xaxis_index, yAxisIndex=_yaxis_index)
s.update(xAxisIndex=_xaxis_index, yAxisIndex=_yaxis_index,
seriesId=self._series_id)
self._chart._option.get('series').append(s)
if is_add_xaxis:

View File

@ -14,11 +14,6 @@ class Page(object):
A composite object to present multiple charts vertically in a single page
"""
def __init__(self, jshost=None, page_title=constants.PAGE_TITLE):
"""
:param jshost:
custom javascript host for the particular chart only
"""
self.__charts = []
self._page_title = page_title
self._jshost = jshost if jshost else constants.CONFIGURATION['HOST']

View File

@ -222,3 +222,29 @@ def test_grid_inverse_yaxis():
grid.add(line_top, grid_bottom='60%')
grid.add(line_bottom, grid_top='50%')
grid.render()
def test_grid_add_overlap():
from pyecharts import Overlap
grid = Grid()
attr = ["{}".format(i) for i in range(1, 13)]
v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
bar = Bar(width=1200, height=600, title="Overlap+Grid 示例", title_pos="40%")
bar.add("蒸发量", attr, v1)
bar.add("降水量", attr, v2, yaxis_formatter=" ml", yaxis_max=250,
legend_pos="85%", legend_orient="vertical", legend_top="45%")
line = Line()
line.add("平均温度", attr, v3, yaxis_formatter=" °C")
overlap = Overlap()
overlap.add(bar)
overlap.add(line, is_add_yaxis=True, yaxis_index=1)
grid.add(overlap, grid_right='20%')
grid.render()