{"id":68,"date":"2026-02-18T11:09:29","date_gmt":"2026-02-18T03:09:29","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=68"},"modified":"2026-01-17T10:13:05","modified_gmt":"2026-01-17T10:13:05","slug":"how-to-create-chart-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-create-chart-using-xlwings\/","title":{"rendered":"How To Create Chart Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>Use the `AddChart2` method of the `Shapes` object to create a chart. The syntax is:\u00a0<\/p>\n<p>sht.api.Shapes.AddChart2(Style, XlChartType, Left, Top, Width, Height, NewLayout)<\/p>\n<p>Where `sht` is the current worksheet. There are 7 parameters, all optional.<\/p>\n<ul>\n<li>Style\uff1aChart style, -1 represents the default style for the chart type<\/li>\n<li>xlChartType\uff1aChart type, using values from the `XlChartType` enumeration, a part of which is listed below<\/li>\n<li>Left\uff1aLeft position of the chart, centered horizontally if omitted<\/li>\n<li>Top\uff1aTop position of the chart, centered vertically if omitted<\/li>\n<li>Width\uff1aWidth of the chart, default is 354 if omitted<\/li>\n<li>Height\uff1aHeight of the chart, default is 210 if omitted<\/li>\n<li>NewLayout\uff1aDetermines the chart layout. If `True`, legends are shown only for composite charts<\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td>\n<p>Name<\/p>\n<\/td>\n<td>\n<p>Value<\/p>\n<\/td>\n<td>\n<p>Description<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlArea<\/p>\n<\/td>\n<td>\n<p>1<\/p>\n<\/td>\n<td>\n<p>Area chart<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlLine<\/p>\n<\/td>\n<td>\n<p>4<\/p>\n<\/td>\n<td>\n<p>Line chart<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlPie<\/p>\n<\/td>\n<td>\n<p>5<\/p>\n<\/td>\n<td>\n<p>Pie chart<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlBarClustered<\/p>\n<\/td>\n<td>\n<p>57<\/p>\n<\/td>\n<td>\n<p>Clustered bar chart<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlBarStacked<\/p>\n<\/td>\n<td>\n<p>58<\/p>\n<\/td>\n<td>\n<p>Stacked bar chart<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlXYScatter<\/p>\n<\/td>\n<td>\n<p>-4169<\/p>\n<\/td>\n<td>\n<p>XY scatter chart<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlBubble<\/p>\n<\/td>\n<td>\n<p>\u4e2a<\/p>\n<\/td>\n<td>\n<p>Bubble chart<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlSurface<\/p>\n<\/td>\n<td>\n<p>83<\/p>\n<\/td>\n<td>\n<p>3D Surface chart<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u2026\u2026<\/p>\n<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>sht.api.Range(&#8216;A1&#8217;).CurrentRegion.Select()<\/p>\n<p>sht.api.Shapes.AddChart2(-1,xw.constants.ChartType.xlColumnClustered,30,150,300,200,True)<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Drawing charts\n\nimport xlwings as xw\nimport os\n\nroot = os.getcwd()\napp = xw.App(visible=True, add_book=False)\nwb=app.books.open(root+r'\/GDP.xlsx',read_only=False)\nsht=wb.sheets(1)\n\nsht.api.Range('B1:H7').Select()\nsht.api.Shapes.AddChart2(-1,xw.constants.ChartType.xlColumnClustered,30,150,300,200,True)\n\n#bk.save()\n#bk.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=\"677\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/65-1.png\" alt=\"Create Chart Using xlwings\" class=\"wp-image-403\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/65-1.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/65-1-300x230.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/65-1-768x589.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":[10],"tags":[],"class_list":["post-68","post","type-post","status-publish","format-standard","hentry","category-xlwings-shape"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/68","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=68"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":404,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions\/404"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}