{"id":94,"date":"2026-03-03T11:23:28","date_gmt":"2026-03-03T03:23:28","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=94"},"modified":"2026-01-17T11:11:51","modified_gmt":"2026-01-17T11:11:51","slug":"how-to-create-a-chart-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-create-a-chart-using-xlwings\/","title":{"rendered":"How To Create a Chart Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>The `charts.add` method provided by the `xlwings` package can be used to create a chart. The syntax is as follows:<\/p>\n<p>\u00a0<\/p>\n<p>sht.charts.add(left=0, top=0, width=355, height=211)<\/p>\n<p>\u00a0<\/p>\n<p>Here, `sht` represents the worksheet object, and there are four parameters:<\/p>\n<p>&#8211; `left` \u2013 Specifies the position of the chart&#8217;s left side, in points. The default value is 0.<\/p>\n<p>&#8211; `top` \u2013 Specifies the position of the chart&#8217;s top side, in points. The default value is 0.<\/p>\n<p>&#8211; `width` \u2013 Specifies the width of the chart, in points. The default value is 355.<\/p>\n<p>&#8211; `height` \u2013 Specifies the height of the chart, in points. The default value is 211.<\/p>\n<p>This method returns a `chart` object.<\/p>\n<p>\u00a0<\/p>\n<p>cht=sht.charts.add(50, 200)\u00a0\u00a0\u00a0 #Add a chart<\/p>\n<p>cht.set_source_data(sht.range(&#8216;A1&#8217;).expand())\u00a0\u00a0\u00a0 #Bind data to chart<\/p>\n<p>cht.chart_type=&#8217;column_clustered&#8217;\u00a0\u00a0\u00a0 #Chart type<\/p>\n<p>cht.api[1].HasTitle=True\u00a0\u00a0\u00a0 #Chart has a title<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Create Chart - xlwings\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(1)\n\ncht=sht.charts.add(50, 200)    #Add a chart\ncht.set_source_data(sht.range('A1').expand())    #Bind data to chart\ncht.chart_type='column_clustered'    #Chart type\ncht.api&#91;1].HasTitle=True    #Chart has a title\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=\"752\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-4.png\" alt=\"Create a Chart Using xlwings\" class=\"wp-image-467\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-4.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-4-300x255.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-4-768x654.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-94","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/94","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=94"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":469,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/94\/revisions\/469"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}