Using MailMerge with Chart Objects and JSON Data
This article explains how to merge JSON data into chart objects using the MailMerge class.

Merging chart objects with data from various data source is very easy using the TXText
TX Text Control supports many standard chart types from bar and pie charts and to 3D radar charts. The out-of-the-box ribbon tabs of TX Text Control can be used to insert and modify the type and appearance.
The following tutorial shows how to insert a chart object and how to connect it to data tables of a loaded JSON file.
-
Consider the following very simple JSON string as a data source. Basically, it contains an array of sales numbers by country.
[ { "country-sales":[ { "country":"United States", "sales":7890567 }, { "country":"Brazil", "sales":780567 }, { "country":"Germany", "sales":889078 }, { "country":"Italy", "sales":442543 }, { "country":"France", "sales":787377 }, { "country":"Spain", "sales":5552365 }, { "country":"Canada", "sales":3466363 } ] } ]
Save this JSON string as a file.
-
In the Reporting ribbon tab, open this JSON data source file by clicking Load JSON File from the Select Data Source drop-down button.
-
Insert your preferred chart type by selecting it from the Chart drop-down list in the Insert ribbon tab.
-
Select the chart object and find the Chart Layout contextual ribbon tab in the Chart Tools ribbon group tab. Click on Set Data Relation to launch the Set Chart Data Relation dialog box.
-
In the opened dialog box, keep the Main Table and Child Table that define the table the data should be used from. The Axis Labels should be set to country and Values to sales.
Close the dialog by clicking OK.
-
Now, find the Preview Merge Fields button in the Reporting ribbon tab. This preview button is not part of the standard ribbon tab, but a sample implementation of this button can be found in the shipped TX Words demo. Essentially, this button is using MailMerge to merge the template with the given data.
When merging this template programmatically using TXText
The template can be completed by adding a title to the chart or by adding additional merge blocks. Play around with the template that can be downloaded here.

Also See
This post references the following in the documentation:
- TXText
Control. Document Server. Mail Merge Class
Windows Forms
Text Control combines the power of a reporting tool and an easy-to-use WYSIWYG word processor - fully programmable and embeddable in your Windows Forms application. TX Text Control .NET for Windows Forms is a royalty-free, fully programmable rich edit control that offers developers a broad range of word processing features in a reusable component for Visual Studio.
Related Posts
ASP.NETWindows FormsMail Merge
Table Extension: Remove Empty Columns After Mail Merge
When you use mail merge to merge repeating blocks, you may end up with blank columns if no data exists for a particular column. Removing empty columns from a table is demonstrated in this example.
An Ultimate Guide to Mail Merge with MS Word Documents in C#
The MailMerge class provides very effective ways to merge data into MS Word compatible templates. This updated ultimate guide provides an overview of all the important features and functionalities…
Using Charts with TX Text Control .NET for Windows 31.0 in .NET 6
The chart controls included in the .NET Framework are deprecated and were not ported to .NET (Core). This article shows how to use a .NET 6 version of the DataVisualization control with TX Text…
Mail Merge with MS Word Documents in C# - An Ultimate Guide
The MailMerge class provides a very effective way to merge data into MS Word compatible templates. This ultimate guide gives an overview of all important features and functionalities of the mail…
Combining MailMerge and Table of Contents
MailMerge is used to merge data into templates from JSON data or IEnumerable objects. This article explains how to combine table of contents with dynamically generated documents using the…