ChartData.add_series() displays number_format integer in PPT until data is accessed
See original GitHub issueHey all,
First time posting so I apologize if I break any conventions. I am using Chart.replace_data to automatically update data on a chart shape in a powerpoint template and I think I may have found a bug. Below you will see my code.
slide=prs.slides[6].shapes
chart_data=ChartData()
chart_data.categories=["CAT1","CAT2","CAT3","CAT4"]
chart_data.add_series("Series Name",(val1,val2,val3,val4), 9)
chart=find_shape_by_name("Chart1").chart
chart.replace_data(chart_data)
For some reason once I save and open the powerpoint, the chart in question displays the number_format (in this case 9) for each category. But in powerpoint if you go to view the data in excel, it contains the correct numbers and will adjust the chart accordingly. I’d like to avoid this additional step as the rest of the powerpoint is being populated automatically.
Thanks for your help!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
ChartData objects — python-pptx 0.6.21 documentation
It provides access to the series label, the series data points, and an optional number format to be applied to each data point...
Read more >Format Number Options for Chart Data Labels in PowerPoint ...
This option is used to display the numbers in general format. Select the Number option within the Category list to access the options...
Read more >Change the data in an existing chart - Microsoft Support
Change chart data on a slide. On the slide, select the chart that you want to change. The Chart Tools contextual tab appears...
Read more >Google Visualization API Reference | Charts
To make a read-only copy of a DataTable (optionally filtered to show specific values, rows, or columns), create a DataView. Each column is...
Read more >Setting Number Format for Chart Data Cell using Aspose.Slides
Class Libraries & REST APIs for the developers to manipulate & process Files from Word, Excel, PowerPoint, Visio, PDF, CAD & several other...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, looks like the documentation got ahead of the implementation. The numeric built-in number formats appear to not have gotten implemented and probably won’t for a while.
I’ll tag this ticket to update the documentation at least for the next release and to get those in there next time we’re in the neighborhood.
I’ve observed the same bug with respect to Axis labels. @inmanenz as a possible workaround, rather than treating this like a functional enum (which it may not be), you may be able to use the format string
"0%"
.If I create a series by using the format string:
chart_data.add_series("Series Name",(val1,val2,val3,val4), '0%')
The axis labels appear as expected, {10%, 20%, … 90%, 100%}
If instead I create the series by using the constant values defined in Excel Number Formats enum (NB: this doesn’t appear to be a part of
pptx.enum.chart
even though it’s listed in the dox beneath that enum…):chart_data.add_series("Series Name",(val1,val2,val3,val4), 9)
The axis labels all appear like: {9, 9, … 9, 9}
As soon as I right-click the chart and “Edit Data” from PowerPoint, then the labels appear properly.