Question

I'm referring this link to draw a pie chart and bar chart below each pie chart.

I've the data which is dynamic, means I can have even 1 pie+bar chart or multiple, depending upon the data I receive.

In the link provided, the placement of location is hardcoded, ie one pie chart at C2 and the other at C18. I dont want to hardcode it rather provide a dynamic value which should place the next pie chart after leaving 2-3 lines.

While using reportlabs to generate PDF, I used showPage() to start from the next page. Is there anything like this in xlsxwriter?

Was it helpful?

Solution

In the link provided, the placement of location is hardcoded, ie one pie chart at C2 and the other at C18. I dont want to hardcode it rather provide a dynamic value which should place the next pie chart after leaving 2-3 lines.

Like the majority of XlsxWriter methods insert_chart() accepts (row, column) notation as wll as "A1" notation. So you can position acharts as follows:

worksheet.insert_chart(3, 4, chart)

If you have a number of charts that you want to position close to each other then you can do something like this:

chart_row = 1
chart_col = 3
chart_offset = 0;

worksheet.insert_chart(chart_row + chart_offset, chart_col, chart1)

# Later...

chart_offset += 15
worksheet.insert_chart(chart_row + chart_offset, chart_col, chart2)

You can also position charts within cells using the offset options shown in the example you linked to.

Refer to the Chart API and Working with Charts documentation for more information.

While using reportlabs to generate PDF, I used showPage() to start from the next page. Is there anything like this in xlsxwriter?

You can set page breaks in the worksheet using the set_h_pagebreaks() method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top