xlsxwriter can not make the chart wider
Asked Answered
F

1

5

I have create a chart by calling

worksheet.insert_chart(chart_row, chart, {'x_scale': 2, 'y_scale': 1})

it is a stacked type.

I want to make the chart horizontal wider, I tried to change x_scale to a big value, it does not do anything to the chart. when I changed it to 0.5, the chart does shrink. it looks like 1, 2, 3,4 value do not make any impact the chart. Any ideas?

Thanks

Foreleg answered 2/4, 2015 at 7:52 Comment(0)
M
11

It should work. Here is an example:

import xlsxwriter

workbook  = xlsxwriter.Workbook('chart.xlsx')
worksheet = workbook.add_worksheet()
chart1    = workbook.add_chart({'type': 'column'})
chart2    = workbook.add_chart({'type': 'column'})

data = [2, 4, 6, 8, 4]
worksheet.write_column('A1', data)

chart1.add_series({'values': '=Sheet1!$A$1:$A$5'})
chart2.add_series({'values': '=Sheet1!$A$1:$A$5'})

worksheet.insert_chart('C1',  chart1)
worksheet.insert_chart('C16', chart2, {'x_scale': 2, 'y_scale': 1})

workbook.close()

And here is the output: enter image description here

Minter answered 2/4, 2015 at 8:18 Comment(6)
I did all the other parts. my chart came out similar, somehow changing the x_scale does not work for me when I try to make it bigger.Foreleg
What version of XlsxWriter are you using? What version of Excel are you using? Also, when you run the above program to you see the same output as the screenshot?Minter
how do I check the version? I am using ubuntu, to open Excel, I use LibreOffice.Foreleg
I notice one thing, the 2 charts you have show different length, is that the scale trying to change, for my case, it does not change at all. I noticed if I have less bars to show, the width of each bar become wider, which is what I want. I wonder if the fixed length of the chart is the real problem.Foreleg
@Kaiyu Li how do I check the version? Like this: python -c 'import xlsxwriter; print(xlsxwriter.__version__)' If the version is less the 0.1.0 of the current version I'd recommend upgrading to the latest version, although I don't remember any issue like this is any of the previous versions.Minter
@Kaiyu Li I use LibreOffice. I tried with LibreOffice 4.4.1.2 and I see something similar to the image above from Excel.Minter

© 2022 - 2024 — McMap. All rights reserved.