{"id":49,"date":"2026-02-11T11:22:25","date_gmt":"2026-02-11T03:22:25","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=49"},"modified":"2026-01-16T07:37:12","modified_gmt":"2026-01-16T07:37:12","slug":"how-to-set-properties-of-series-in-charts-using-openpyxl","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-set-properties-of-series-in-charts-using-openpyxl.html","title":{"rendered":"How To Set Properties of Series in Charts Using OpenPyXL?"},"content":{"rendered":"<h2>Method<\/h2>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Get the first series and modify its properties<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">ser=chart.series[0]<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">ser.graphicalProperties.line.solidFill=&#8217;00FF00&#8242;<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">ser.graphicalProperties.line.Width=600000<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">ser.graphicalProperties.line.dashStyle=&#8217;sysDot&#8217;<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Series\n\n# Import relevant modules such as Workbook, load_workbook,\n# and charts from openpyxl\nfrom openpyxl import Workbook, load_workbook\nfrom openpyxl.chart import LineChart, Reference, Series\n\n# Read the file\nwb = load_workbook('Sales.xlsx')\n# Select the first worksheet\nws = wb.worksheets&#91;0]\n\n# Get the data from the range B1:D6 and save it as a Reference object\ndata = Reference(ws, min_col=2, min_row=1, max_col=4, max_row=6)\n# Get the data from the range A2:A6 for the x-axis of the bar chart\nlabels = Reference(ws, min_col=1, min_row=2, max_col=1, max_row=6)\n\n# Create a bar chart object\nchart = LineChart()\n# Set the data source\nchart.add_data(data, titles_from_data=True)\n# Set x-axis labels\nchart.set_categories(labels)\n\n#Get the first series and modify its properties\nser=chart.series&#91;0]\nser.graphicalProperties.line.solidFill='00FF00'\nser.graphicalProperties.line.Width=600000\nser.graphicalProperties.line.dashStyle='sysDot'\n\n# Set chart and axis titles\nchart.title='Product Sales'\nchart.x_axis.title='Product Name'\nchart.y_axis.title='Sales'\n\n# Insert the bar chart into a specified cell\nws.add_chart(chart, 'E2')\n\n# Save the file\nwb.save('test.xlsx')<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"680\" src=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/31.png\" alt=\"Set Properties of Series in Charts Using OpenPyXL\" class=\"wp-image-317\" srcset=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/31.png 872w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/31-300x234.png 300w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/31-768x599.png 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>OpenPyXL<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-openpyxl-chart"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":2,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":318,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/49\/revisions\/318"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}