Inserting Chart Axis Title Dynamically in Presentation Document
Leave feedback
NoteThe example reads the shop data described in The Business Layer.
Please follow below steps to create a column chart in MS PowerPoint 2013:
- Create a new presentation slide
- Click the “Insert” tab, and then click “Chart” in the illustrations group to open the “Insert Chart” dialogue box
- Select “Column” in the sidebar, you will see a gallery of charts
- Select the “100% Stacked Column” and press “OK” to insert the chart and Worksheet template to your document
- Edit the Worksheet with your data to update the chart
- Save your Document
As a report developer, you are required to share orders quantity of the customers dynamically with the following key requirements:
- Report must show quantity of sales/orders
- Sales/orders quantity must be represented by Quarters
- It must associate order quantity with the corresponding customer
- Report must be generated in the Presentation Document
<<[title]>>foreach [in orders.Where(c => c.OrderDate.Year == 2015)
.GroupBy(c => c.Customer)
.OrderBy(g => g.Key.CustomerName)]>>
<<x [Key.CustomerName]>>
| 1st Quarter<<y [Where(c => c.Date.Month >= 1 && c.Date.Month <= 3).Sum(c => c.ProductQuantity)]>> | 2nd Quarter<<y [Where(c => c.Date.Month >= 4 && c.Date.Month <= 6).Sum(c => c.ProductQuantity)]>> | 3rd Quarter<<y [Where(c => c.Date.Month >= 7 && c.Date.Month <= 9).Sum(c => c.ProductQuantity)]>> | 4th Quarter<<y [Where(c => c.Date.Month >= 10 && c.Date.Month <= 12).Sum(c => c.ProductQuantity)]>> |
Category 1 | 4.3 | 2.4 | 2 | 3 |
Category 2 | 2.5 | 4.4 | 2 | 2 |
Category 3 | 3.5 | 1.8 | 3 | 5 |
Category 4 | 4.5 | 2.8 | 5 | 2 |
Please download the sample Chart Template we created in this article:
import json
from datetime import datetime
from groupdocs.assembly import DataSourceInfo, DocumentAssembler
def parse_dates(item):
# JSON has no dates: turn the order dates into datetime objects for the template
for key in ("OrderDate", "ShippingDate"):
if key in item:
item[key] = datetime.strptime(item[key], "%Y-%m-%dT%H:%M:%S")
return item
with open("orders.json", encoding="utf-8") as f:
orders = json.load(f, object_hook=parse_dates)
assembler = DocumentAssembler()
assembler.assemble_document("chart-with-filtering-and-dynamic-title.pptx", "chart-with-filtering-and-dynamic-title-report.pptx", [
DataSourceInfo(orders, "orders"),
DataSourceInfo("Harbor Lane orders by customer, 2015", "title"),
])
The following sample file is used in this example: chart-with-filtering-and-dynamic-title.pptx
The following sample file is used in this example: orders.json
Binary file (PPTX, 46 KB)
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.