0

replace_data in python pptx seems to replace the data from the excel sheet of the chart data, which can be found when we right click on any chart and click on edit data. But the changes do not reflect on the data labels associated with the chart in the ppt. Can anyone help me how to update this ppt data labels? Look at the chart image below:

https://i.stack.imgur.com/xdJoB.jpg

Code:

chart_data = CategoryChartData()

for i in range(1):
    #i=1
    data = df[:5]     # 5 values to insert at once 
    data= data.iloc[::-1].reset_index(drop= True)
    chart_data.categories = data['Unnamed: 0'].tolist()
    chart_data.add_series(series_name, tuple(data['Unnamed: 2']))  
    chart = shapes_by_id[chart_idx].chart   # chart_idx is the chart index
    # since there are more than one chart in one slide
    chart.replace_data(chart_data)
df.drop(df[:5].index,inplace = True)
df.reset_index(drop =True,inplace=True)

Below is the dataframe image:

https://i.stack.imgur.com/6b7Xk.png

Mr Anonymous
  • 75
  • 10
  • Are the labels actually data labels on the slide or are they static text boxes that look like data labels? You have to set that up in powerpoint. Then any changes you make to the data via pptx will be reflected in the slide. – Eric Truett Apr 20 '20 at 13:43
  • Those are data labels. When I hover my mouse pointer over it, it shows the updated data label and corresponding data point. @EricTruett – Mr Anonymous Apr 20 '20 at 13:50
  • You should post your python code. – Eric Truett Apr 20 '20 at 13:57
  • @EricTruett Added the script. Please check. – Mr Anonymous Apr 20 '20 at 14:24
  • If you open the PowerPoint and choose Edit Values In Excel on the chart, do the values update? – scanny Apr 20 '20 at 17:39
  • The length of the bar changes according to the value entered. But the data labels remain as it is. It still shows the X.X% – Mr Anonymous Apr 20 '20 at 17:46
  • hey @scanny can you help me with this? I am stuck at this part. If you want more info to understand my problem, do tell me. Thanks – Mr Anonymous Apr 22 '20 at 13:31
  • I think you're going to need to look at the XML for the data labels and work out what's happening. Maybe the `X.X%` is a text label and you need to either remove the text or replace it with a string representation of the value. This latter bit you would need to do data-point by data-point. – scanny Apr 22 '20 at 17:40
  • @scanny thank you. The data labels are updated. Now can you please help me with this? https://stackoverflow.com/questions/61383528/how-to-read-text-boxes-inside-the-chart-area-python-pptx – Mr Anonymous Apr 23 '20 at 09:16

0 Answers0