# Using MailMerge with Chart Objects and JSON Data

> TX Text Control MailMerge populates chart objects with JSON data by mapping axis labels and values to data columns. The ribbon provides a Set Data Relation dialog to configure chart bindings, and the merge process fills charts automatically alongside text fields and merge blocks.

- **Author:** Bjoern Meyer
- **Published:** 2019-07-18
- **Modified:** 2026-03-05
- **Description:** TX Text Control MailMerge populates chart objects with JSON data by mapping axis labels and values to data columns. The ribbon provides a Set Data Relation dialog to configure chart bindings, and the merge process fills charts automatically alongside text fields and merge blocks.
- **3 min read** (449 words)
- **Tags:**
  - Charts
  - Mail Merge
  - Windows Forms
- **Web URL:** https://www.textcontrol.com/blog/2019/07/18/using-mailmerge-with-chart-objects-and-json-data/
- **LLMs URL:** https://www.textcontrol.com/blog/2019/07/18/using-mailmerge-with-chart-objects-and-json-data/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2019/07/18/using-mailmerge-with-chart-objects-and-json-data/llms-full.txt

---

Merging chart objects with data from various data source is very easy using the TXTextControl.DocumentServer.MailMerge class.

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.

1. 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.
2. In the *Reporting* ribbon tab, open this JSON data source file by clicking *Load JSON File* from the *Select Data Source* drop-down button.
3. Insert your preferred chart type by selecting it from the *Chart* drop-down list in the *Insert* ribbon tab.
    
    ![Insert chart object](https://s1-www.textcontrol.com/assets/dist/blog/2019/07/18/a/assets/insert-chart.webp "Insert chart object")
4. 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.
    
    ![Insert chart object](https://s1-www.textcontrol.com/assets/dist/blog/2019/07/18/a/assets/chart-values.webp "Insert chart object")
5. 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*.
    
    ![Insert chart object](https://s1-www.textcontrol.com/assets/dist/blog/2019/07/18/a/assets/set-data.webp "Insert chart object")
    
    Close the dialog by clicking *OK*.
6. 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.
    
    ![Insert chart object](https://s1-www.textcontrol.com/assets/dist/blog/2019/07/18/a/assets/preview.webp "Insert chart object")

When merging this template programmatically using TXTextControl.DocumentServer.MailMerge class, chart objects are merged automatically based on the relation specified in the template.

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](https://s1-www.textcontrol.com/assets/dist/blog/2019/07/18/a/assets/sales-report.zip).

![Insert chart object](https://s1-www.textcontrol.com/assets/dist/blog/2019/07/18/a/assets/styled.webp "Insert chart object")

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Table Extension: Remove Empty Columns After Mail Merge](https://www.textcontrol.com/blog/2023/06/08/table-extension-remove-empty-columns-after-mail-merge/llms.txt)
- [An Ultimate Guide to Mail Merge with MS Word Documents in C#](https://www.textcontrol.com/blog/2023/06/07/an-ultimate-guide-to-mail-merge-with-ms-word-documents-in-csharp/llms.txt)
- [Using Charts with TX Text Control .NET for Windows 31.0 in .NET 6](https://www.textcontrol.com/blog/2022/11/02/using-charts-with-tx-text-control-net-for-windows-3100-in-net-6/llms.txt)
- [Mail Merge with MS Word Documents in C# - An Ultimate Guide](https://www.textcontrol.com/blog/2022/05/25/mail-merge-with-ms-word-documents-in-csharp-an-ultimate-guide/llms.txt)
- [Combining MailMerge and Table of Contents](https://www.textcontrol.com/blog/2022/03/22/combining-mailmerge-and-table-of-contents/llms.txt)
- [Merging Form Fields using the MailMerge Class](https://www.textcontrol.com/blog/2022/02/21/merging-form-fields-using-the-mailmerge-class/llms.txt)
- [MailMerge: Rendering Conditional Table Rows](https://www.textcontrol.com/blog/2022/02/17/mailmerge-rendering-conditional-table-rows/llms.txt)
- [Merging Merge Block Cells Vertically with Matching Content](https://www.textcontrol.com/blog/2021/10/20/vertically-merge-table-cells-of-merge-blocks-for-matching-content/llms.txt)
- [Windows Forms Ribbon: Displaying User-Friendly Merge Field Names](https://www.textcontrol.com/blog/2020/01/14/displaying-user-friendly-merge-field-names-in-the-ribbon/llms.txt)
- [Merge Excel Documents into MailMerge Templates using IncludeText Fields](https://www.textcontrol.com/blog/2019/08/13/merge-excel-documents-into-mailmerge-templates/llms.txt)
- [MailMerge: Conditional Table Cell Colors using Filter Instructions](https://www.textcontrol.com/blog/2019/06/06/mailmerge-conditional-table-cell-colors-using-filter-instructions/llms.txt)
- [MailMerge: Using Filters to Remove Unwanted Rows](https://www.textcontrol.com/blog/2019/06/04/mailmerge-using-filters-to-remove-unwanted-rows/llms.txt)
- [MailMerge: Conditional Rendering of Merge Blocks](https://www.textcontrol.com/blog/2018/11/28/mailmerge-conditional-rendering-of-merge-blocks/llms.txt)
- [DataSourceManager: Using the Ready-to-Use Reporting Dialog Boxes](https://www.textcontrol.com/blog/2018/11/27/datasourcemanager-using-the-ready-to-use-reporting-dialog-boxes/llms.txt)
- [Different Ways to Create Documents using Text Control Products](https://www.textcontrol.com/blog/2017/10/17/ways-to-create-documents-using-text-control-products/llms.txt)
- [Windows Forms: Preview Mail Merge Results with the BindingNavigator and a BindingSource](https://www.textcontrol.com/blog/2016/01/08/windows-forms-preview-mail-merge-results-with-the-bindingnavigator-and-a-bindingsource/llms.txt)
