Newb here just getting into Python and ran into an issue that's beating me down. I have the following excerpt of Python code to create a PPT slide from an existing template. The layout and placeholders are correct but I can't get it to run with my data listed below (x, y_in, & y_out). Any help is greatly appreciated.
x = [datetime.datetime(2017, 8, 4, 15, 5, tzinfo=<FixedOffset u'+00:00' datetime.timedelta(0)>), datetime.datetime(2017, 8, 4, 15, 10, tzinfo=<FixedOffset u'+00:00' datetime.timedelta(0)>), datetime.datetime(2017, 8, 4, 15, 15, tzinfo=<FixedOffset u'+00:00' datetime.timedelta(0)>), datetime.datetime(2017, 8, 4, 15, 20, tzinfo=<FixedOffset u'+00:00' datetime.timedelta(0)>)]
y_in = [780993, 538962, 730180, 1135936]
y_out = [5631489, 6774738, 6485944, 6611580]
prs = Presentation('Network_Utilization_template_master.pptx')
slide = prs.slides.add_slide(prs.slide_layouts[2])
placeholder = slide.placeholders[17]
chart_data = CategoryChartData()
chart_data.categories = x
chart_data.add_series(y_in)
chart_data.add_series(y_out)
graphic_frame = placeholder.insert_chart(XL_CHART_TYPE.LINE, chart_data)
chart = graphic_frame.chart
chart.has_legend = True
chart.legend.include_in_layout = True
chart.series[0-2].smooth = True
prs.save("Network_Utilization_" + today_s + ".pptx")
the compiler spits out the following:
Traceback (most recent call last):
File "/Users/jemorey/Documents/pptx-2.py", line 81, in <module>
graphic_frame = placeholder.insert_chart(XL_CHART_TYPE.LINE, chart_data)
File "/Users/jemorey/Library/Python/2.7/lib/python/site-packages/pptx/shapes/placeholder.py", line 291, in insert_chart
rId = self.part.add_chart_part(chart_type, chart_data)
File "/Users/jemorey/Library/Python/2.7/lib/python/site-packages/pptx/parts/slide.py", line 174, in add_chart_part
chart_part = ChartPart.new(chart_type, chart_data, self.package)
File "/Users/jemorey/Library/Python/2.7/lib/python/site-packages/pptx/parts/chart.py", line 29, in new
chart_blob = chart_data.xml_bytes(chart_type)
File "/Users/jemorey/Library/Python/2.7/lib/python/site-packages/pptx/chart/data.py", line 104, in xml_bytes
return self._xml(chart_type).encode('utf-8')
File "/Users/jemorey/Library/Python/2.7/lib/python/site-packages/pptx/chart/data.py", line 128, in _xml
return ChartXmlWriter(chart_type, self).xml
File "/Users/jemorey/Library/Python/2.7/lib/python/site-packages/pptx/chart/xmlwriter.py", line 803, in xml
'ser_xml': self._ser_xml,
File "/Users/jemorey/Library/Python/2.7/lib/python/site-packages/pptx/chart/xmlwriter.py", line 902, in _ser_xml
'tx_xml': xml_writer.tx_xml,
File "/Users/jemorey/Library/Python/2.7/lib/python/site-packages/pptx/chart/xmlwriter.py", line 191, in tx_xml
'series_name': self.name,
File "/Users/jemorey/Library/Python/2.7/lib/python/site-packages/pptx/chart/xmlwriter.py", line 121, in name
return escape(self._series.name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/sax/saxutils.py", line 32, in escape
data = data.replace("&", "&")
AttributeError: 'list' object has no attribute 'replace'
x = [1,2,3,4]? - David Zemensadd_seriesmethod appears to take as it's first argument astrobject representing the series Name. you're only passing a list, and I think that's causing the error. python-pptx.readthedocs.io/en/latest/user/charts.html - David Zemens