程式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | from pptx import Presentation from pptx.chart.data import CategoryChartData from pptx.enum.chart import XL_CHART_TYPE from pptx.util import Inches import requests import json r = requests.get('https://data.moa.gov.tw/Service/OpenData/FromM/AquaticTransData.aspx') text = json.loads(r.text) tranDate = [] totalPrince = [] for row in text: if '吳郭魚' in row['魚貨名稱'] and '斗南' in row['市場名稱']: tranDate.append(row['交易日期']) totalPrince.append(row['平均價']*row['交易量']) prs = Presentation() slide = prs.slides.add_slide(prs.slide_layouts[5]) title = slide.shapes.title title.text = "吳郭魚在斗南市場的交易圖" chart_data = CategoryChartData() chart_data.categories = tranDate chart_data.add_series('吳郭魚', tuple(totalPrince)) x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5) slide.shapes.add_chart( XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data ) prs.save("吳郭魚在斗南市場的交易圖.pptx") |
執行結果:
沒有留言:
張貼留言