How to change/add chart data series in python-pptx? -
i'm trying set data in existing chart using python-pptx.
from pptx import presentation pres_path = "c:\\pres.pptx" pres = presentation(pres_path) pres.slides[3].shapes[4].chart.series[0].values
(92.0, 330.0, 309.0, 313.0, 356.0, 421.0, 457.0)
pres.slides[3].shapes[4].chart.series[0].values = (1,2,3) traceback (most recent call last): file "<input>", line 1, in <module> attributeerror: can't set attribute
there's method mentioned in documentation seems relevant, can't understand how use it: http://python-pptx.readthedocs.org/en/latest/_modules/pptx/chart/data.html
pres.slides[3].shapes[4].chart.replace_data((1,2,3)) traceback (most recent call last): file "<input>", line 1, in <module> file "c:\python27\lib\site-packages\pptx\chart\chart.py", line 119, in replace_data _seriesrewriter.replace_series_data(self._chartspace, chart_data) file "c:\python27\lib\site-packages\pptx\chart\chart.py", line 197, in replace_series_data sers = cls._adjust_ser_count(chartspace, len(chart_data.series)) attributeerror: 'tuple' object has no attribute 'series'
i'd appreciate can provide. thanks!
to add new series existing table behind chart need 3 things:
- create instance of chartdata()
- provide category name
add new series chartdata() object, using "add_series()" func.
chart_data = chartdata() chart_data.categories = 'category_name' col_idx, col in enumerate(single_df.columns): chart_data.add_series(col, (single_df.ix[:, col_idx].values)) shp.chart.replace_data(chart_data)
Comments
Post a Comment