{"id":516,"date":"2026-03-26T11:02:19","date_gmt":"2026-03-26T03:02:19","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=516"},"modified":"2026-03-23T06:12:45","modified_gmt":"2026-03-23T06:12:45","slug":"how-to-set-properties-of-line-graphic-elements-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-properties-of-line-graphic-elements-using-xlwings\/","title":{"rendered":"How To Set Properties of Line Graphic Elements Using xlwings?"},"content":{"rendered":"<p>\u3010<b>Method<\/b>\u3011<\/p>\n<p>By referencing the `Format.Line` property of a Series object, a `LineFormat` object is returned, representing the line object in the series. The members of the `LineFormat` object are used to set the line properties.<\/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<p style=\"margin: 0in; font-size: 16.0pt;\"><span lang=\"zh-CN\" style=\"font-family: 'Microsoft YaHei';\">\u3010<\/span><span lang=\"en-US\" style=\"font-weight: bold; font-family: Calibri;\">Example<\/span><span lang=\"zh-CN\" style=\"font-family: 'Microsoft YaHei';\">\u3011<\/span><\/p>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"768\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-01-1.jpg\" alt=\"\" class=\"wp-image-1103\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-01-1.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-01-1-300x262.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-01-1-768x670.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n\n\n\n<p>\u00a0\u00a0<br>\u3010<strong>Code<\/strong>\u3011<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Line chart element settings\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\nser=cht.SeriesCollection('P1')\nser.Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((0,255,0))\nser.Format.Fill.ForeColor.ObjectThemeColor=10\nser.Format.Fill.ForeColor.SchemeColor=3\nser2.Format.Line.DashStyle=4\nser2.Format.Line.ForeColor.RGB=xw.utils.rgb_to_int((0,0,255))\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=\"880\" height=\"768\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-03.jpg\" alt=\"\" class=\"wp-image-1104\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-03.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-03-300x262.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-03-768x670.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Method<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-516","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/516","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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=516"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/516\/revisions"}],"predecessor-version":[{"id":1105,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/516\/revisions\/1105"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}