積み上げ棒グラフがあり、グラフの周りに境界線を置いていますが、グラフの「線」属性はありません:python pptxのグラフにボーダーを追加するにはどうすればいいですか
from pptx.chart.data import ChartData
from pptx.enum.chart import XL_CHART_TYPE, XL_TICK_MARK, XL_LABEL_POSITION, XL_LEGEND_POSITION
from pptx.dml.color import RGBColor
from pptx.util import Inches, Pt
# define chart data
chart_data = ChartData()
chart_data.categories = ['East', 'West', 'Midwest']
chart_data.add_series('Series 1', (19.2, 21.4, 16.7))
chart_data.add_series('Series 2', (10.2, 11.4, 6.7))
chart_data.add_series('Series 3', (2.2, 8.4, 1.7))
# add chart to slide
x, y, cx, cy = Inches(1), Inches(1), Inches(5), Inches(3.5)
ThisChart = ThisSlide.shapes.add_chart(
XL_CHART_TYPE.COLUMN_STACKED, x, y, cx, cy, chart_data
).chart # the '.chart' is getting the chart object from the chart creation
#Put a border around the chart *This is the part that not working *
ThisBorder = ThisChart.line # <--- there is no line attribute
ThisBorder.color.rgb = RGBColor(0xFF, 0x00, 0x00) # hex
ThisBorder.width = inches(0.1)
#Give the chart a title
ThisChart.chart_title.has_text_frame = True
ThisChart.chart_title.text_frame.text = "My Chart Title"
# Give the chart a legend
ThisChart.has_legend = True
ThisChart.legend.position = XL_LEGEND_POSITION.RIGHT
ThisChart.legend.include_in_layout = False
ThisChart.legend.font.size = Pt(11)
#add data labels
plot = ThisChart.plots[0] # The first Series
plot.has_data_labels = True # display the value on the bar
plot.overlap = 100 # make the bars stacked
data_labels = plot.data_labels
data_labels.font.size = Pt(11)
data_labels.font.color.rgb = RGBColor(0,0,0)
data_labels.number_format = "#,##0"
ThisChart.value_axis.has_minor_gridlines = False
ThisChart.value_axis.has_major_gridlines = False
ThisChart.value_axis.tick_labels.font.size = Pt(12)
ThisChart.value_axis.tick_labels.number_format = "#,##0"
ThisChart.category_axis.tick_labels.font.size = Pt(12)
# Colour the bars, I'm not going to really use these colours, just getting things working :)
ThisChart.series[0].fill.solid()
ThisChart.series[0].fill.fore_color.rgb = RGBColor(244,66,152) # Pink hex: F44298, RGB: 244,66,152
ThisChart.series[1].fill.solid()
ThisChart.series[1].fill.fore_color.rgb = RGBColor(66,134,244) # Blue hex: 4286F4, RGB: 66,134,244
ThisChart.series[2].fill.solid()
ThisChart.series[2].fill.fore_color.rgb = RGBColor(92,244,66) # Green hex: 5CF442, RGB: 92,244,66
グラフ領域に境界線を設定する別の方法はありますか?凡例を含むチャート領域の周りに薄い黒い境界線を探してください。私はスライド上に4つのチャートを持つ予定です。
あなたはpython-pptxを意味しますか? (python-docxではなく) –
はい、まあ、私はそれを修正しました。私はそれらの両方を執筆し、時々私の子供の名前のようにそれらを混ぜる:) – scanny