Merging chart objects with data from various data source is very easy using the TXTextControl.DocumentServer.MailMerge class TX Text Control .NET for Windows Forms
DocumentServer Namespace
MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services.
.

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
    }
    ]
    }
    ]
    view raw data.json hosted with ❤ by GitHub

    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

  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

  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

    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

When merging this template programmatically using TXTextControl.DocumentServer.MailMerge class TX Text Control .NET for Windows Forms
DocumentServer Namespace
MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services.
, 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.

Insert chart object