简体   繁体   中英

PPTX Python - How to fix ValueError: chart data contains no categories for a LineChart?

I'm trying to replace data in an existing line chart in Python PPTX. Here's the code I'm using:

   for chart in charts:
       chart_data = CategoryChartData()
       chart_index = list(charts).index(chart)
       scenario_no = chart_index + 1
       sc_df = wrk_df[wrk_df['Scenario No'] == scenario_no]
       for category in sc_df['categories'].tolist():
           chart_data.add_category(category)
       chart_data.add_series('Volume', sc_df['Series 1'].tolist())
       chart_data.add_series('Value', sc_df['Series 2'].tolist())
       chart.replace_data(chart_data)

Basically there are several charts on the slide, through which the code iterates and replaces the data. The charts themselve have a numeric x axis and two series.

When I run this code I get the following error:

ValueError: chart data contains no categories

I've already tried converting the new categories into string, however, it doesn't work with any data type. I'm also able to print original category labels in the existing chart, which means it does have categories.

I can't think of what's going wrong here. Does anyone have any solution for this or at least any knowledge of why this is happenning?

It turned out that the data being passed as categories was empty

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM