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.

    Loading...

    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 , 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