如何将 chart.y_axis 类别更改为数字
How to change chart.y_axis category to number
我正在尝试将 x_axis 类别更改为数字,因为图表如下所示。
这是我在 python 中使用 openpyxl
的代码
chart = LineChart()
chart.title = f'{key}-{date()}'
chart.height = 14
chart.width = 30
chart.y_axis = Typed(expected_type=NumericAxis)
data = Reference(ws, min_col=2, min_row=1, max_row=y, max_col=z)
cats = Reference(ws, min_col=1, min_row=2, max_row=y, max_col=1)
chart.add_data(data, titles_from_data=True)
chart.set_categories(cats)
ws.add_chart(chart, "B2")
writer.save()
(我想要的是显示数字,如“50000000”而不是“5E+09”)
enter image description here
enter image description here
解决方案:-将所有单元格格式更改为数字
df.to_excel(writer, sheet_name='`sheets name`')
y = len(df.index)
z = len(df.columns)
writer = pd.ExcelWriter('`filename`', engine='openpyxl')
ws = writer.sheets['`sheets name`']
for i in range(1, z):
for e in range(1, y):
cell = ws.cell(e, i)
cell.number_format = '0'
我正在尝试将 x_axis 类别更改为数字,因为图表如下所示。 这是我在 python 中使用 openpyxl
的代码 chart = LineChart()
chart.title = f'{key}-{date()}'
chart.height = 14
chart.width = 30
chart.y_axis = Typed(expected_type=NumericAxis)
data = Reference(ws, min_col=2, min_row=1, max_row=y, max_col=z)
cats = Reference(ws, min_col=1, min_row=2, max_row=y, max_col=1)
chart.add_data(data, titles_from_data=True)
chart.set_categories(cats)
ws.add_chart(chart, "B2")
writer.save()
(我想要的是显示数字,如“50000000”而不是“5E+09”)
enter image description here
enter image description here
解决方案:-将所有单元格格式更改为数字
df.to_excel(writer, sheet_name='`sheets name`')
y = len(df.index)
z = len(df.columns)
writer = pd.ExcelWriter('`filename`', engine='openpyxl')
ws = writer.sheets['`sheets name`']
for i in range(1, z):
for e in range(1, y):
cell = ws.cell(e, i)
cell.number_format = '0'