Chart Series Coloring in Presentation Document
Leave feedback
NoteThis feature is supported by version 18.5 or greater.
NoteThe code uses some of the objects defined in The Business Layer.
Practising the following steps, you can insert 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” dialog 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. See Chart Data (Excel).
- Save your Document
As a report developer, you are required to share contract price by manager dynamically with the following key requirements:
- The report must show the name of the manager
- The report must show the total contract price for each manager
- Series color to be used in chart series
- The report must be generated in the Presentation Document
<Total Contract Prices by Managers<<foreach [m in
managers]>><<x [m.Manager]>>
Total Contract Price«y [m.Total_Contract_Price]»«seriesColor [color]» | |
---|---|
Category 1 | 4.3 |
Category 2 | 2.5 |
Category 3 | 3.5 |
Category 4 | 4.5 |
TipFor detailed technical information about syntax, expressions and report generation by the engine, please visit: Working with GroupDocs.Assembly Engine
Please download the sample Dynamic Chart Series Color document we created in this article:
- Chart Template.pptx (Template for CustomObject and JSON examples)
For a chart with dynamic data, you can set colors of chart series dynamically based upon expressions. To use the feature, do the following steps:
Declare a chart with dynamic data in the usual way
For chart series to be colored dynamically, define corresponding color expressions in names of these series using seriesColor tags having the following syntax:
<<seriesColor [color_expression]>>
A color expression must return a value of one of the following types:
- A string containing the name of a known color, that is, the case-insensitive name of a member of the KnownColor enumeration such as “red”
- An integer value defining RGB (red, green, blue) components of the color such as 0xFFFF00 (yellow)
- A value of the Color type
Following code snippet generates the report:
// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET | |
try | |
{ | |
// Setting up source open document template | |
const String strDocumentTemplate = "Presentation Templates/Dynamic Chart Series Color.pptx"; | |
//setting up data source document | |
const string dataSrcDocument = "Presentation DataSource/Managers Data.pptx"; | |
//Setting up destination open document report | |
const String strDocumentReport = "Presentation Reports/Dynamic Chart Series Color.pptx"; | |
//Define serires color | |
string color = "red"; | |
// Set table column names to be extracted from the document. | |
DocumentTableOptions options = new DocumentTableOptions(); | |
options.FirstRowContainsColumnNames = true; | |
DocumentTable table = new DocumentTable(CommonUtilities.GetDataSourceDocument(dataSrcDocument), 1, options); | |
// NOTE: For non-Spreadsheet documents, the type of a document table column is always string by default. | |
Debug.Assert(table.Columns["Total_Contract_Price"].Type == typeof(string)); | |
// Change the column's type to double thus enabling to use arithmetic operations on values of the column | |
// such as summing in templates. | |
table.Columns["Total_Contract_Price"].Type = typeof(double); | |
// Pass DocumentTable as a data source. | |
DocumentAssembler assembler = new DocumentAssembler(); | |
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate), | |
CommonUtilities.SetDestinationDocument(strDocumentReport), | |
new DataSourceInfo(table,"managers"), | |
new DataSourceInfo(color,"color")); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
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.