a:graphic (Graphic)
Container for graphical objects including charts, SmartArt, and embedded graphical content.
Parent elements
Child elements
Description
\:graphic\ is the DrawingML element that encapsulates graphical objects (charts, tables, SmartArt) within a graphical frame. It is defined in ECMA-376 Part 1 §20.1.2.5.
The graphic element serves as the primary container for:
- Charts — Data visualization (bar, line, pie, area, stock charts, etc.)
- SmartArt — Structured diagramming (hierarchies, processes, cycles, relationships)
- Tables — Tabular data presentation
- OLE objects — Embedded Office objects (external content)
- Custom graphics — Extensible framework for graphic content types
Graphic objects differ from:
- Shapes (\:sp) — Simple geometric shapes with fill/line
- Pictures (\:pic) — Image/photograph embedding
- Connectors (\:cxnSp) — Connecting lines between shapes
Graphics provide:
- Complex visual layouts and data representation
- Embedded analytical content
- Dynamic data binding (charts)
- Professional infographics and diagrams
- Office-native content integration
Attributes
| Attribute | Type | Values | Description |
|---|---|---|---|
| (none) | - | - | \:graphic\ has no attributes; all content specified via child elements. |
Content Model
\:graphic\ contains exactly one child element:
- a:graphicData (required, 1) — Container for graphic-specific data
The \:graphicData\ element specifies:
- URI — Namespace/type identifier for graphic content
- Content — Type-specific graphic data (chart XML, SmartArt content, etc.)
Child Elements Table
| Element | Occurrence | Description |
|---|---|---|
| \:graphicData\ | 1 (required) | Graphics data container with URI and type-specific content. |
Examples
Embedded Chart (Column Chart)
<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart">
<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<c:chart>
<c:title><c:tx><c:rich><a:p><a:pPr algn="ctr"/><a:r><a:rPr lang="en-US"/><a:t>Sales Data</a:t></a:r></a:p></c:rich></c:tx></c:title>
<c:plotArea>
<c:barChart>
<!-- Chart series and data -->
</c:barChart>
</c:plotArea>
</c:chart>
</c:chartSpace>
</a:graphicData>
</a:graphic>
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Drawing.Charts;
var graphic = new Graphic();
var graphicData = new GraphicData
{
Uri = "http://schemas.openxmlformats.org/drawingml/2006/chart"
};
// Create chart content (simplified)
var chartSpace = new ChartSpace();
var chart = new Chart();
var title = new Title();
var tx = new Tx();
var rich = new RichText();
var paragraph = new Paragraph();
var run = new Run();
var text = new Text { Text = "Sales Data" };
run.Append(text);
paragraph.Append(run);
rich.Append(paragraph);
tx.Append(rich);
title.Append(tx);
chart.Append(title);
chartSpace.Append(chart);
graphicData.Append(chartSpace);
graphic.Append(graphicData);
SmartArt Diagram (Hierarchy)
<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/smartart">
<p:spTree xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
<!-- SmartArt layout and shapes -->
<p:sp>
<p:nvSpPr>
<p:cNvPr id="1" name="Executive"/>
<p:cNvSpPr/>
<p:nvPr/>
</p:nvSpPr>
<p:spPr/>
<p:txBody><a:bodyPr/><a:lstStyle/><a:p><a:r><a:t>CEO</a:t></a:r></a:p></p:txBody>
</p:sp>
</p:spTree>
</a:graphicData>
</a:graphic>
var graphic = new Graphic();
var graphicData = new GraphicData
{
Uri = "http://schemas.openxmlformats.org/drawingml/2006/smartart"
};
// SmartArt content uses Presentation ML shape tree (p:spTree)
// Typically generated by Office tools rather than manually created
// Contains shape definitions for hierarchy, flowchart, etc.
graphic.Append(graphicData);
Table (Tabular Data)
<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/table">
<a:tbl>
<a:tblPr firstRow="1">
<a:tableStyleId>{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}</a:tableStyleId>
</a:tblPr>
<a:tblGrid>
<a:gridCol w="2000000"/>
<a:gridCol w="2000000"/>
</a:tblGrid>
<a:tr h="600000">
<a:tc><a:txBody><a:p><a:r><a:t>Name</a:t></a:r></a:p></a:txBody></a:tc>
<a:tc><a:txBody><a:p><a:r><a:t>Value</a:t></a:r></a:p></a:txBody></a:tc>
</a:tr>
</a:tbl>
</a:graphicData>
</a:graphic>
var graphic = new Graphic();
var graphicData = new GraphicData
{
Uri = "http://schemas.openxmlformats.org/drawingml/2006/table"
};
var table = new DocumentFormat.OpenXml.Drawing.Table();
// Table properties
var tblPr = new TableProperties { FirstRow = true };
table.Append(tblPr);
// Grid (column definitions)
var tblGrid = new TableGrid();
var gridCol1 = new GridColumn { Width = 2000000 };
var gridCol2 = new GridColumn { Width = 2000000 };
tblGrid.Append(gridCol1);
tblGrid.Append(gridCol2);
table.Append(tblGrid);
// Header row
var headerRow = new TableRow { Height = 600000 };
var cell1 = new TableCell();
var txBody1 = new TextBody();
var p1 = new Paragraph();
var r1 = new Run();
r1.Append(new Text { Text = "Name" });
p1.Append(r1);
txBody1.Append(p1);
cell1.Append(txBody1);
headerRow.Append(cell1);
// Add more cells...
table.Append(headerRow);
graphicData.Append(table);
graphic.Append(graphicData);
OLE Object (Embedded Content)
<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject">
<o:OleObject xmlns:o="urn:schemas-microsoft-com:office:office" Type="Embed" ProgID="Excel.Sheet.12" ShapeID="101" DrawAspect="Content" ObjectID="_1000" r:id="rId4" UpdateMode="Always"/>
</a:graphicData>
</a:graphic>
var graphic = new Graphic();
var graphicData = new GraphicData
{
Uri = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"
};
// OLE object embedding (typically handled by Office automation)
// Contains relationship reference to embedded object
// ProgID identifies object type (Excel.Sheet.12, Word.Document.12, etc.)
graphic.Append(graphicData);
Minimal Graphic (Empty Structure)
<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart"/>
</a:graphic>
var graphic = new Graphic();
var graphicData = new GraphicData
{
Uri = "http://schemas.openxmlformats.org/drawingml/2006/chart"
};
graphic.Append(graphicData);
GraphicData URI Types Reference
Common namespace URIs for graphic content:
| URI | Content Type | Purpose |
|---|---|---|
| \http://schemas.openxmlformats.org/drawingml/2006/chart\ | Chart | Data visualization (bar, line, pie charts) |
| \http://schemas.openxmlformats.org/drawingml/2006/smartart\ | SmartArt | Diagrams (hierarchy, process, cycle) |
| \http://schemas.openxmlformats.org/drawingml/2006/table\ | Table | Tabular data and formatting |
| \http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject\ | OLE Object | Embedded objects with relationship IDs |
| \http://schemas.openxmlformats.org/presentationml/2006/main\ | Presentation Content | Presentation-specific shapes/content |
Graphic Frame Relationship
Graphic elements always appear within a graphical frame:
`xml
`
The frame provides:
- Transform (\p:xfrm) — Position and size
- Graphic (\:graphic) — Content specification
Common Patterns
Chart Type Reference
| Chart Type | URI | Common Use |
|---|---|---|
| Column/Bar | \chart\ | Comparison across categories |
| Line | \chart\ | Trends over time |
| Pie | \chart\ | Parts of whole |
| Area | \chart\ | Cumulative trends |
| Stock | \chart\ | Financial data |
| Surface | \chart\ | 3D data visualization |
SmartArt Diagram Types
| Diagram | Purpose |
|---|---|
| Hierarchy | Organizational structures, family trees |
| Process | Step-by-step flows, workflows |
| Cycle | Circular/repeating processes |
| Relationship | Connections, matrices |
| Matrix | 2D positioning of elements |
| Pyramid | Hierarchical levels, importance |
Interaction with Presentation Elements
Graphics integrate with:
- Graphical Frame (\p:graphicFrame) — Container providing position/size
- Relationships — Charts and OLE objects use relationship IDs
- Slides — Graphics appear on presentation slides
- Masters — Can be placed on master slides as templates
Notes
Element Characteristics
- Required parent: Must be child of \p:graphicFrame\ (Presentation ML) or \c:chartSpace\ (Chart ML)
- Content type-specific: Content structure varies by graphic type
- Relationship-dependent: Charts often use relationship IDs to data sources
- Read-only metadata: Most Office apps generate graphic content
- Extensible framework: URI-based system allows custom graphic types
Content Authoring
- Charts: Use Office charting APIs (Excel.Chart.* or OfficeOpenXml.Chart)
- SmartArt: Generated by SmartArt layout engines (typically not hand-coded)
- Tables: Can be manually created but visual properties limited
- OLE Objects: Created via Office Automation or Package APIs
- Direct editing: XML editing possible but not recommended without tool support
Rendering
- PowerPoint: Full support for all graphic types
- Word: Charts, tables, OLE objects supported
- Excel: Charts, SmartArt, embedded objects
- Publisher: Full graphic support
Performance
- Charts with large datasets can impact file size/performance
- SmartArt diagrams are complex (many nested shapes)
- Tables render efficiently
- OLE objects depend on embedded object size
Best Practices
- Use Office object models for reliable graphic creation
- Validate chart data integrity
- Document SmartArt diagrams for maintenance
- Use relationships for external data sources
- Test graphics across Office applications
- Consider accessibility (alt text for graphics)
- Keep embedded objects reasonably sized
Compatibility
- Office 2007 and later
- Chart, table, SmartArt consistently supported
- OLE objects require corresponding application
- Some older Office versions limit graphic complexity
- PDF export may simplify complex graphics