python pptx如何根据XL_CHART_TYPE.LINE更改图表中的行格式

时间:2018-06-05 10:29:06

标签: python python-pptx

如何根据XL_CHART_TYPE.LINE?

访问图表中系列的行格式对象
chart_data = ChartData()
vec2 = [ float(i.value) for i in xl_sheet.col(1)]
chart_data.categories = [ datetime.datetime.fromordinal(int(693594+i.value )) for i in xl_sheet.col(0)]
uu=chart_data.add_series('Model1',    tuple(vec2))

我没有通过

访问系列行的格式
uu.format.line.color.rgb = RGBColor((100,100,100)) 

1 个答案:

答案 0 :(得分:1)

创建图表后,您可以通过该行代表的系列访问每一行:

graphic_frame = slide.shapes.add_chart(..chart_data,..)
# ---graphic frame is the shape containing the chart, not the chart itself---
chart = graphic_frame.chart
# ---get the desired series from the chart---
series = chart.series[0]
# ---series.format is a ChartFormat object, which in turn provides access to
#    the LineFormat object for that series---
line = series.format.line
# ---change the line style, color, etc. the same way as for any other line---
line.color.rgb = RGBColor(255, 0, 0)