前提・実現したいこと
python、openpyxlを利用して、積上げ棒・折れ線グラフを一つのグラフエリアに表示する「複合グラフ」を作成したいです。
複合グラフの作成ができず困っています。
対応方法について、ご教授願います。
また、そもそもopenpyxlを使用した場合は複合グラフの作成は実施(サポートされていない)できないのでしょうか?
発生している問題・エラーメッセージ
積上げ棒、折れ線グラフ単体では作成できるが、複合グラフの作成ができない
該当のソースコード
python3.8.2
1import openpyxl 2from openpyxl.chart import BarChart, LineChart, Reference 3from openpyxl.chart.plotarea import DataTable 4 5wb = openpyxl.load_workbook("./sample.xlsx") 6sh = wb['list'] 7 8labels = Reference(sh, min_col=1, max_col=1, min_row=3, max_row=sh.max_row) 9# 棒グラフ用 10data1 = Reference(sh, min_col=2, max_col=6, min_row=2, max_row=sh.max_row) 11# 折れ線グラフ用 12# data2 = Reference(sh, min_col=2, max_col=6, min_row=2, max_row=sh.max_row) 13data2 = Reference(sh, min_col=5, max_col=6, min_row=2, max_row=sh.max_row) 14chart = BarChart() 15chart.type = "col" 16chart.grouping = "stacked" 17 18chart.overlap = 100 19chart.title = "メインタイトル" 20chart.y_axis.title = "数量" 21chart.legend.position = 'b' 22chart.add_data(data1, titles_from_data=True) 23chart.set_categories(labels) 24 25chart2 = LineChart() 26chart2.add_data(data2, titles_from_data=True) 27 28chart.height = 10 29chart.width = 15 30 31# datatble 32chart.plot_area.dTable = DataTable() 33chart.plot_area.dTable.showHorzBorder = True 34chart.plot_area.dTable.showVertBorder = True 35chart.plot_area.dTable.showOutline = True 36chart.plot_area.dTable.showKeys = True 37 38sh.add_chart(chart, "I2") 39sh.add_chart(chart2, "I20") 40 41wb.save("./sample.xlsx") 42
試したこと
1.グラフ単体で作成できることを確認
2.グラフが複数作成できることを確認
補足情報(FW/ツールのバージョンなど)
●グラフ作成時の入力データ
title
date 100-10 200-10 300-10 gokei base
9/16 15 48 41 104 50
9/17 15 48 46 109 50
9/18 15 50 50 115 50
9/19 15 50 49 114 50
9/20 15 49 49 113 50
※"100-10","200-10","300-10"を積上げ棒グラフ
※"gokei","base"を折れ線グラフ
※最終的には"gokei"の折れ線グラフを非表示にし、データラベルの設定を実施したい
ここにより詳細な情報を記載してください。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/09/20 22:06