ONLYOFFICE / DesktopEditors

An office suite that combines text, spreadsheet and presentation editors allowing to create, view and edit local documents
https://www.onlyoffice.com
Other
2.65k stars 312 forks source link

Missing chart from python-pptx #1458

Open m-fariz-a opened 6 months ago

m-fariz-a commented 6 months ago

This issue is unique.

Operating System

Linux (RPM package)

Version information

7.5.1.23 (flatpak)

Expected Behavior

image image

The chart is rendered properly

Actual Behavior

image image

The column bar chart is missing, while the stacked bar chart is not rendered properly

Reproduction Steps

  1. Install onlyoffice (mine is flatpak version in Fedora 39 workstation)
  2. Install python-pptx package
    $ pip install python-pptx
  3. Run the python file to generate the presentation file
$ python chart.py

This is the code for chart.py

from pptx import Presentation
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches

prs = Presentation()

# column bar chart
slide = prs.slides.add_slide(prs.slide_layouts[5])
categories = ['East', 'West', 'Midwest', 'North', 'South']
values = {
    'Series 1-testing': (2.5, 3, 3.5, 3.1, 2.8),
    'Series 2': (4, 3.3, 2.9, 3.9, 2.2),
    'Series c': (2.1, 3.4, 3.2, 3.5, 2.3),
    'Series ###': (2.1, 3.4, 3.2, 2.7, 2.9),
}
chart_data = CategoryChartData()
chart_data.categories = categories
for series_name, series_values in values.items():
    chart_data.add_series(series_name, series_values, '0.00')
# add chart to slide --------------------
x, y, cx, cy = (Inches(2), Inches(2), Inches(6), Inches(4.5))
barchart = slide.shapes.add_chart(
    XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data
).chart

# horizontal bar chart
slide = prs.slides.add_slide(prs.slide_layouts[5])
categories = ['East', 'West', 'Midwest', 'North', 'South']
values = {
    'Series 1-testing': (2.5, 3, 3.5, 3.1, 2.8),
    'Series 2': (4, 3.3, 2.9, 3.9, 2.2),
    'Series c': (2.1, 3.4, 3.2, 3.5, 2.3),
    'Series ###': (2.1, 3.4, 3.2, 2.7, 2.9),
}
chart_data = CategoryChartData()
chart_data.categories = categories
for series_name, series_values in values.items():
    chart_data.add_series(series_name, series_values, '0.00%')
x, y, cx, cy = (Inches(0.25), Inches(1.75), Inches(6.75), Inches(2.5))
barhchart = slide.shapes.add_chart(
    XL_CHART_TYPE.BAR_CLUSTERED, x, y, cx, cy, chart_data
).chart

# stacked horizontal bar chart
slide = prs.slides.add_slide(prs.slide_layouts[5])
categories = ['East', 'West', 'Midwest', 'North', 'South']
values = {
    'Series 1-testing': (40, 30, 10, 60, 20),
    'Series 2': (40, 20, 30, 25, 10),
    'Series c': (20, 50, 60, None, 10),
    'Series ###': (20, 50, None, 15, 60),
    'Series _+fd3' : (20, 50, None, 15, 60),
}
chart_data = CategoryChartData()
chart_data.categories = categories
for series_name, series_values in values.items():
    chart_data.add_series(series_name, series_values, '0.00%')
# add chart to slide --------------------
x, y, cx, cy = (Inches(0.25), Inches(1.75), Inches(6.75), Inches(2.5))
stacked_barhchart = slide.shapes.add_chart(
    XL_CHART_TYPE.BAR_STACKED, x, y, cx, cy, chart_data
).chart

# add table
slide = prs.slides.add_slide(prs.slide_layouts[5])
x, y, cx, cy = Inches(2), Inches(2), Inches(4), Inches(1.5)
shape = slide.shapes.add_table(2, 2, x, y, cx, cy)

table = shape.table
cell = table.cell(0, 0)
cell.text = 'Unladen Swallow'
cell = table.cell(0, 1)
cell.text = 'Unladen Swallow 2'

cell = table.cell(1, 0)
cell.text = 'This is me'
cell = table.cell(1, 1)
cell.text = 'This is me 2'

prs.save('chart-01.pptx')

Additional information

I have already tested in some office application such as LibreOffice, WPS Office, and Microsoft Office and the chart result is rendered properly.

Sometimes I need to generate repetitive slide in presentation file using this method.

SergeyLuzyanin commented 6 months ago

Hello, @m-fariz-a. Could you attach chart-01.pptx, please.

m-fariz-a commented 6 months ago

Hello, @SergeyLuzyanin ,

Sure, Here's the file

chart-01.zip

Rita-Bubnova commented 6 months ago

@m-fariz-a, Thanks for the file, we will check it.

SergeyLuzyanin commented 5 months ago

@m-fariz-a, Most of the problems with correct rendering of the charts from your file will be fixed in the next version. I fixed the incorrect rendering columns and bars - https://github.com/ONLYOFFICE/sdkjs/commit/895270b30771dd31b448ca057eded14377f8616f and problem with the number format of labels of values axes - https://github.com/ONLYOFFICE/sdkjs/commit/4763519c0c8097105c6ea3357eab765863479416 There is only one problem left - the labels of the categories axis of the chart from the 3rd slide are rotated, while PowerPoint renders them without rotation. We will fix it in the future. Thanks again for the file.

m-fariz-a commented 5 months ago

@SergeyLuzyanin Thanks a lot. I'm really glad to know that this will be getting better in the next release.

Rita-Bubnova commented 5 months ago

There is only one problem left - the labels of the categories axis of the chart from the 3rd slide are rotated, while PowerPoint renders them without rotation.

I can confirm - this is bug, issue #47013..