Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Openpyxl make LineChart
#1
Hi all,
I want to use openpyxl make LineChart as Line with markers style.
when run code get new chart need to modify Horizontal axis crosses-->Axis Value to -2.2 that can show normally.
Where could get the parameter about "the Horizontal axis crosses-->Axis Value", thanks in advance!

import openpyxl
from openpyxl.chart import Reference, LineChart
from openpyxl.chart.axis import DateAxis
from random import randint


wb = openpyxl.load_workbook('offset_demo.xlsx')
sheet = wb.active


values = Reference(sheet,
                   min_col=3,
                   max_col=37,
                   min_row=1,
                   max_row=152)


chart = LineChart()
chart.height=13
chart.width=32


chart.add_data(values, titles_from_data=True)
dates=Reference(sheet,min_col=1,min_row=2,max_row=152)
chart.set_categories(dates)

chart.legend=None
chart.y_axis.crossAx=500
chart.y_axis.scaling.min=-2
chart.y_axis.scaling.max=0.5

chart.x_axis=DateAxis(crossAx=100)
chart.x_axis.number_format='dd-mm-yy'
chart.x_axis.majorTimeUnit='days'

for i in range(0,35):
    s1 = chart.series[i]
    s1.marker.symbol = "auto"
    s1.graphicalProperties.solidFill ="%06x" % randint(0,0xFFFFFF)
    s1.marker.graphicalProperties.line.solidFill ="%06x" % randint(0,0xFFFFFF)
    s1.graphicalProperties.dashStyle = "dash"
    s1.graphicalProperties.line.width = 1000

chart.title = "OffSet Trend"

chart.x_axis.title = "Date"

chart.y_axis.title = "Offset Value"

sheet.add_chart(chart,"A2")

wb.save("offset_demo.xlsx")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Openpyxl overwrite Linechart SamLiu 0 875 Nov-26-2022, 05:44 AM
Last Post: SamLiu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020