{"id":103,"date":"2026-03-07T17:03:16","date_gmt":"2026-03-07T09:03:16","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=103"},"modified":"2026-01-17T11:23:44","modified_gmt":"2026-01-17T11:23:44","slug":"how-to-set-series-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-series-using-xlwings\/","title":{"rendered":"How To Set Series Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>Each Chart object has a `SeriesCollection` property, which returns a collection containing all series in the chart. What is a series? In a composite bar chart, each row of data corresponds to a composite bar, and within each composite bar, there are two different-colored individual bars. All individual bars of the same color form a series. Therefore, the chart has two series. A series is represented by a Series object.<\/p>\n<p>In the example below, the second series is referenced, and its `ChartType` property is used to change the chart type to a line chart. The `Smooth` property is set to `True` to smooth the line. The `MarkerStyle` property is used to set the markers at data points as triangles, and the `MarkerForegroundColor` property sets the marker color to blue. The `HasDataLabel` property is set to `True` to display data labels.<\/p>\n<p>sht.api.Range(&#8216;A1:B7&#8217;).Select()<\/p>\n<p>cht=sht.api.Shapes.AddChart().Chart<\/p>\n<p>ser2=cht.SeriesCollection(&#8216;P2&#8217;)\u00a0\u00a0\u00a0 #Second series<\/p>\n<p>ser2.ChartType=xw.constants.ChartType.xlLine\u00a0\u00a0\u00a0 #Line chart<\/p>\n<p>ser2.Smooth=True\u00a0\u00a0\u00a0 #Smooth processing<\/p>\n<p>ser2.MarkerStyle=xw.constants.MarkerStyle.xlMarkerStyleTriangle\u00a0\u00a0\u00a0 #Markers<\/p>\n<p>ser2.MarkerForegroundColor=xw.utils.rgb_to_int((0,0,255))\u00a0\u00a0\u00a0 #Color<\/p>\n<p>ser2.HasDataLabels=True\u00a0\u00a0\u00a0 #Data labels<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Set series\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'\/P1P2.xlsx',read_only=False)\nsht=wb.sheets(1)\n\nsht.api.Range('A1:B7').Select()\ncht=sht.api.Shapes.AddChart().Chart\nser2=cht.SeriesCollection('P2')    #Second series\nser2.ChartType=xw.constants.ChartType.xlLine    #Line chart\nser2.Smooth=True    #Smooth processing\nser2.MarkerStyle=xw.constants.MarkerStyle.xlMarkerStyleTriangle    #Markers\nser2.MarkerForegroundColor=xw.utils.rgb_to_int((0,0,255))    #Color\nser2.HasDataLabels=True    #Data labels\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=\"557\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-11.png\" alt=\"Set Series Using xlwings\" class=\"wp-image-490\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-11.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-11-300x189.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-11-768x484.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-103","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/103","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=103"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":491,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/103\/revisions\/491"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}