简体   繁体   English

Python pptx折线的折线图

[英]Python pptx Line chart with discontinued lines

I am trying to generate line chart using python-pptx, and I am able to generate chart using below code. 我正在尝试使用python-pptx生成折线图,并且能够使用以下代码生成图表。

chart_data = ChartData()
chart_data.categories = ['Q1 Sales', 'Q2 Sales', 'Q3 Sales']
chart_data.add_series('West',    (32.2, 28.4, 34.7))
chart_data.add_series('East',    (24.3, 30.6, 20.2))
chart_data.add_series('Midwest', (20.4, 18.3, 26.2))

x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
chart = slide.shapes.add_chart(
    XL_CHART_TYPE.LINE, x, y, cx, cy, chart_data
).chart

chart.has_legend = True
chart.legend.include_in_layout = False

This will generate a graph like this http://python-pptx.readthedocs.org/en/latest/_images/chart-06.png a line series with three points. 这将生成一个图表,如http://python-pptx.readthedocs.org/en/latest/_images/chart-06.png一个有三个点的系列。

My requirement is- for "East" I don't have second point, so the line for "East" should be a breaking line, only two point will show first and third. 我的要求是 - 对于“东方”我没有第二点,所以“东方”的线应该是一条突破线,只有两点将显示第一和第三。

I tried below by making it empty but didn't work 我在下面尝试将其设为空但不起作用

chart_data.add_series('East',    (24.3, "", 20.2))

Is there any way to achieve this? 有没有办法实现这个目标? Its possible in high charts but not supported in ppt. 它可能在高图表中但在ppt中不受支持。

I am trying to achieve something like this: 我想要实现这样的事情: 在此输入图像描述

Thanks in advance. 提前致谢。

I ran into the same issue and when I passed None into python-pptx I got the gaps just like in highcharts. 我遇到了同样的问题,当我将Non传递给python-pptx时,我得到的差距就像在highcharts中一样。

That is, instead of passing in an empty string pass in None. 也就是说,而不是传入一个空字符串传递无。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM