{"id":97,"date":"2026-03-04T17:07:23","date_gmt":"2026-03-04T09:07:23","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=97"},"modified":"2026-01-17T11:15:48","modified_gmt":"2026-01-17T11:15:48","slug":"how-to-create-a-chart-by-adding-series-one-by-one","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-create-a-chart-by-adding-series-one-by-one\/","title":{"rendered":"How To Create a Chart by Adding Series One by One?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>A chart can also be created by adding series one by one.<\/p>\n<p>\u00a0<\/p>\n<p>sht.api.Range(&#8216;A2:A7&#8217;).Select()\u00a0\u00a0\u00a0 #Data<\/p>\n<p>shp=sht.api.Shapes.AddChart2(-1, xw.constants.ChartType.xlColumnClustered, 200, 20, 350, 250, True)<\/p>\n<p>cht=shp.Chart\u00a0\u00a0\u00a0 #Add chart<\/p>\n<p>\u00a0<\/p>\n<p>ser=cht.SeriesCollection().NewSeries()<\/p>\n<p>ser.ChartType=xw.constants.ChartType.xlLine<\/p>\n<p>ser.Values=sht.api.Range(&#8220;B2:B7&#8221;)<\/p>\n<p>\u00a0<\/p>\n<p>cht.HasLegend=True<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Create chart - Add series one by one\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\nsht.api.Range('B2:B7').Select()    #Data\nshp=sht.api.Shapes.AddChart2(-1, xw.constants.ChartType.xlColumnClustered, 200, 20, 350, 250, True)\ncht=shp.Chart    #Add chart\n\nser=cht.SeriesCollection().NewSeries()\nser.ChartType=xw.constants.ChartType.xlLine\nser.Values=sht.api.Range(\"C2:C7\")\n  \ncht.HasLegend=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=\"582\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-7.png\" alt=\"Create a Chart by Adding Series One by One\" class=\"wp-image-476\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-7.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-7-300x198.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-7-768x506.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-97","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/97","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=97"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":478,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/97\/revisions\/478"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}