Scatter Chart in Spreadsheet Document

Note
In this article, we will use GroupDocs.Assembly to generate a Scatter Chart report in Spreadsheet Document format based on the use case: Working with a Business Case.
Note
The code uses some of the objects defined in The Business Layer.

Scatter Chart in Microsoft Excel Document

Creating a Scatter Chart

Please follow below steps to create Scatter Chart in MS Excel 2013:

  1. Add a new Workbook.
  2. Click in the workbook where you want to insert the chart, click the “Insert” tab, and then click “Insert Scatter Chart Icon” in the charts group.
  3. A drop-down with charts will appear, select the “Scatter” and press “OK” to insert the chart.
  4. Click on the chart you just inserted, then click the “Change Data” icon in Data group.
  5. Now add legend entries. See Chart Data.
  6. Save your Document.

Reporting Requirement

As a report developer, you are required to show your customers’ orders prices by month with the following key requirements:

  • Report must show information on a Scatter Chart.
  • It must indicate Price of each order by month.
  • Report must be generated in the Spreadsheet Document.

Adding Syntax to be evaluated by GroupDocs.Assembly Engine

Chart Title

Total Order Prices by Months<<foreach [in orders
.GroupBy(c => c.OrderDate.Month)]>>

Chart Data

Legend Entries

="Total Order Price<<x [Key]>><<y [Sum(c => c.Price)]>>"
Tip
For detailed technical information about syntax, expressions and report generation by the engine, please visit: Working with GroupDocs.Assembly Engine.

Download Scatter Chart Template

Please download the sample Scatter Chart document we created in this article:

Generating The Report

Custom Objects

// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
//Setting up source spreadsheet template
const String strSpreadsheetTemplate = "Spreadsheet Templates/Scatter Chart.xlsx";
//Setting up destination document report
const String strSpreadsheetReport = "Spreadsheet Reports/Scatter Chart Report.xlsx";
try
{
//Instantiate DocumentAssembler class
DocumentAssembler assembler = new DocumentAssembler();
//Call AssembleDocument to generate Scatter Chart Report in spreadsheet format
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strSpreadsheetTemplate),
CommonUtilities.SetDestinationDocument(strSpreadsheetReport),
new DataSourceInfo(DataLayer.GetOrdersData(), "orders"));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Database Entities

// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
//Setting up source spreadsheet template
const String strSpreadsheetTemplate = "Spreadsheet Templates/Scatter Chart_DB.xlsx";
//Setting up destination document report
const String strSpreadsheetReport = "Spreadsheet Reports/Scatter Chart_DB Report.xlsx";
try
{
//Instantiate DocumentAssembler class
DocumentAssembler assembler = new DocumentAssembler();
//Call AssembleDocument to generate Scatter Chart Report in spreadsheet format
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strSpreadsheetTemplate),
CommonUtilities.SetDestinationDocument(strSpreadsheetReport),
new DataSourceInfo(DataLayer.GetOrdersDataDB(), "orders"));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Using DataSet

// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
//Setting up source spreadsheet template
const String strSpreadsheetTemplate = "Spreadsheet Templates/Scatter Chart_DB.xlsx";
//Setting up destination document report
const String strSpreadsheetReport = "Spreadsheet Reports/Scatter Chart_DT Report.xlsx";
try
{
//Instantiate DocumentAssembler class
DocumentAssembler assembler = new DocumentAssembler();
//Call AssembleDocument to generate Scatter Chart Report in spreadsheet format
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strSpreadsheetTemplate),
CommonUtilities.SetDestinationDocument(strSpreadsheetReport),
new DataSourceInfo(DataLayer.GetCustomersAndOrdersDataDT()));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Using XML DataSource

// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
//Setting up source spreadsheet template
const String strSpreadsheetTemplate = "Spreadsheet Templates/Scatter Chart_DB.xlsx";
//Setting up destination document report
const String strSpreadsheetReport = "Spreadsheet Reports/Scatter Chart_XML Report.xlsx";
try
{
//Instantiate DocumentAssembler class
DocumentAssembler assembler = new DocumentAssembler();
//Call AssembleDocument to generate Scatter Chart Report in spreadsheet format
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strSpreadsheetTemplate),
CommonUtilities.SetDestinationDocument(strSpreadsheetReport),
new DataSourceInfo(DataLayer.GetAllDataFromXML(), "ds"));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Using JSON DataSource

// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
//setting up source
const String strDocumentTemplate = "Spreadsheet Templates/Scatter Chart.xlsx";
//Setting up destination
const String strDocumentReport = "Spreadsheet Reports/Scatter Chart_Json Report.xlsx";
try
{
//Instantiate DocumentAssembler class
DocumentAssembler assembler = new DocumentAssembler();//initialize object of DocumentAssembler class
//Call AssembleDocument to generate Scatter Chart report in spreadsheet format
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate),
CommonUtilities.SetDestinationDocument(strDocumentReport),
new DataSourceInfo(DataLayer.GetCustomerOrderDataFromJson(), "orders"));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Scatter Chart in OpenOffice Spreadsheet 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.