Column Chart in Word Processing Document

Note
The code uses some of the objects defined in The Business Layer.

Column Chart in Microsoft Word Document

Creating a Column Chart

Practicing the following steps, you can insert a Column Chart in MS Word 2013:

  1. Click in the document where you want to insert the chart, click the “Insert” tab, and then click “Chart” in the illustrations group to open the “Insert Chart” dialogue box.
  2. Select “Column” in the sidebar, you will see a gallery of charts.
  3. Select the “100% Stacked Column” and press “OK” to insert the chart and Worksheet template to your document.
  4. Edit the Worksheet with your data to update the chart. See Chart Data (Excel).
  5. Save your Document.

Reporting Requirement

As a report developer, you are required to share orders quantity of the customers dynamically with the following key requirements:

  • A report must show the quantity of sales/orders.
  • Sales/orders quantity must represented by Quarters.
  • It must associate order quantity with the corresponding customer.
  • A report must be generated in the Word Processing Document.

Adding Syntax to be evaluated by GroupDocs.Assembly Engine

Chart Title

Total Order Quantity by Quarters<<foreach [in orders
.Where(c => c.OrderDate.Year == 2015)
.GroupBy(c => c.Customer)
.OrderBy(g => g.Key.CustomerName)]>><<x [Key.CustomerName]>>

Chart Data (Excel)

 

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

Tip
For detailed technical information about syntax, expressions and report generation by the engine, please visit: Working with GroupDocs.Assembly Engine.

Download Template

Please download the sample Chart with Filtering, Grouping, and Ordering document we created in this article:

Generating The Report

Custom Objects

Note
The code uses some of the objects defined in The Business Layer
// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
//Setting up source document template
const String strDocumentTemplate = "Word Templates/Chart with Filtering, Grouping, and Ordering.docx";
//Setting up destination document report
const String strDocumentReport = "Word Reports/Chart with Filtering, Grouping, and Ordering Report.docx";
try
{
//Instantiate DocumentAssembler class
DocumentAssembler assembler = new DocumentAssembler();
//Call AssembleDocument to generate Chart report with Filtering, Grouping, and Ordering in document format
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate),
CommonUtilities.SetDestinationDocument(strDocumentReport),
new DataSourceInfo(DataLayer.GetOrdersData(), "orders"));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Database Entities

Note
The code uses some of the objects defined in The Business Layer
// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
//Setting up source document template
const String strDocumentTemplate = "Word Templates/Chart with Filtering, Grouping, and Ordering_DB.docx";
//Setting up destination document report
const String strDocumentReport = "Word Reports/Chart with Filtering, Grouping, and Ordering_DB Report.docx";
try
{
//Instantiate DocumentAssembler class
DocumentAssembler assembler = new DocumentAssembler();
//Call AssembleDocument to generate Chart report with Filtering, Grouping, and Ordering in document format
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate),
CommonUtilities.SetDestinationDocument(strDocumentReport),
new DataSourceInfo(DataLayer.GetOrdersDataDB(), "orders"));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Using DataSet

Note
The code uses some of the objects defined in The Business Layer
// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
//Setting up source document template
const String strDocumentTemplate = "Word Templates/Chart with Filtering, Grouping, and Ordering_DB.docx";
//Setting up destination document report
const String strDocumentReport = "Word Reports/Chart with Filtering, Grouping, and Ordering_DT Report.docx";
try
{
//Instantiate DocumentAssembler class
DocumentAssembler assembler = new DocumentAssembler();
//Call AssembleDocument to generate Chart report with Filtering, Grouping, and Ordering in document format
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate),
CommonUtilities.SetDestinationDocument(strDocumentReport),
new DataSourceInfo(DataLayer.GetCustomersAndOrdersDataDT()));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Using XML DataSource

Note
The code uses some of the objects defined in The Business Layer
// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
//Setting up source document template
const String strDocumentTemplate = "Word Templates/Chart with Filtering, Grouping, and Ordering_XML.docx";
//Setting up destination document report
const String strDocumentReport = "Word Reports/Chart with Filtering, Grouping, and Ordering_XML Report.docx";
try
{
//Instantiate DocumentAssembler class
DocumentAssembler assembler = new DocumentAssembler();
//Call AssembleDocument to generate Chart report with Filtering, Grouping, and Ordering in document format
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate),
CommonUtilities.SetDestinationDocument(strDocumentReport),
new DataSourceInfo(DataLayer.GetAllDataFromXML(), "ds"));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Using JSON DataSource

Note
The code uses some of the objects defined in The Business Layer
// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
//setting up source
const String strDocumentTemplate = "Word Templates/Chart with Filtering, Grouping, and Ordering.docx";
//Setting up destination
const String strDocumentReport = "Word Reports/Chart with Filtering, Grouping, and Ordering_Json Report.docx";
try
{
//Instantiate DocumentAssembler class
DocumentAssembler assembler = new DocumentAssembler();//initialize object of DocumentAssembler class
//Call AssembleDocument to generate Chart with Filtering, Grouping, and Ordering report in document format
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate),
CommonUtilities.SetDestinationDocument(strDocumentReport),
new DataSourceInfo(DataLayer.GetCustomerOrderDataFromJson(), "orders"));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Column Chart in OpenOffice Document

To be investigated.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.