{"id":95,"date":"2026-03-03T18:41:17","date_gmt":"2026-03-03T10:41:17","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=95"},"modified":"2026-01-17T11:13:11","modified_gmt":"2026-01-17T11:13:11","slug":"how-to-create-a-chart-using-the-api","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-create-a-chart-using-the-api\/","title":{"rendered":"How To Create a Chart Using the API?"},"content":{"rendered":"<h2>Method<\/h2>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">cht=sht.api.ChartObjects().Add(20,200,355,211).Chart<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">cht.SetSourceData(sht.api.Range(&#8216;A1:H7&#8217;),1)<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">cht.ChartType=xw.constants.ChartType.xlColumnClustered<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">cht.HasTitle=True<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Create Chart - xlwings API\n\nimport xlwings as xw\nimport os\n\nroot = os.getcwd()\napp = xw.App(visible=True, add_book=False)\nwb=app.books.open('GDP.xlsx',read_only=False)\nsht=wb.sheets('Sheet1')\n\ncht=sht.api.ChartObjects().Add(20,200,355,211).Chart\ncht.SetSourceData(sht.api.Range('A1:H7'),1)\ncht.ChartType=xw.constants.ChartType.xlColumnClustered\ncht.HasTitle=True\n\n#wb.save()\n#wb.close()\n#app.kill()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"768\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-5.png\" alt=\"Create a Chart Using the API\" class=\"wp-image-470\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-5.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-5-300x261.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-5-768x668.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Method<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-95","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/95","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=95"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/95\/revisions"}],"predecessor-version":[{"id":472,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/95\/revisions\/472"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}