# Integrating Charts and Barcodes

> Set up charts and barcodes in Windows Forms: ChartFrame and BarcodeFrame, the DataVisualization package for .NET, the ribbon tabs and TXBarcodeCore SVG.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Integration Guide > Integrating Charts and Barcodes
- **2837 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/integration/charts-barcodes/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/integration/charts-barcodes/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/integration/charts-barcodes/llms-full.txt

---

Charts and barcodes are objects in a TX Text Control document, placed like images and saved with the document. Each one is backed by a control that draws it: a chart by the chart control of `System.Windows.Forms.DataVisualization`, a barcode by the barcode control of TX Text Control. The barcode control is in the TX Text Control package; the chart control has to be added to .NET projects separately. What each needs in your project, how the ribbon offers them to users and where your code inserts and updates them is described below, together with barcodes as SVG images.

What users do with charts and barcodes in the editor, such as formatting and positioning them, is the subject of [Charts and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/charts-barcodes/llms-full.txt) in the Document Editor section.

### What Each Object Is Made of

|  | Chart | Barcode |
|---|---|---|
| The object in the document | [ChartFrame](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-datavisualization/chartframe/llms-full.txt) | [BarcodeFrame](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-datavisualization/barcodeframe/llms-full.txt) |
| The control that draws it | `System.Windows.Forms.DataVisualization.Charting.Chart` | [TXBarcodeControl](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecontrol/llms-full.txt) in `TXTextControl.Barcode` |
| All of them in the text part with the input focus | [TextControl.Charts](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/charts-property/llms-full.txt) | [TextControl.Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/barcodes-property/llms-full.txt) |
| The assemblies | *TXTextControl.dll* and the chart assembly | *TXBarcode.dll* and *TXBarcode.Windows.Forms.dll*, in the package |

The frame handles the position of the object in the text: inline like a character, anchored to a paragraph or at a fixed place on the page. The control holds the content: the data and the appearance of the chart, the type and the text of the barcode. Your code reaches the control through the frame's [Chart](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-datavisualization/chartframe/chart-property/llms-full.txt) or `Barcode` property.

### Add the Chart Control to the Project

A chart frame can only be used when the assembly with the chart control is available. How it gets into your project depends on the framework:

- **.NET Framework.** `System.Windows.Forms.DataVisualization` is part of the .NET Framework since version 4. Add a reference to the assembly *System.Windows.Forms.DataVisualization* in **Reference Manager**, under **Assemblies**.
- **.NET 8 or higher.** Microsoft did not port the chart control to .NET. You install a package built from Text Control's fork of a .NET port, as [Migrating from .NET Framework to .NET](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/installation/upgrading/from-dotnet-framework/#charts) describes step by step.

With the chart control in the project, the chart commands of the ribbon work, and your code can create charts. Barcodes need no extra step: their assemblies come with `TXTextControl.TextControl.WinForms.SDK`.

### Offer Charts and Barcodes in the Ribbon

The ribbon offers charts and barcodes through three of its predefined tabs: the **Chart** and **Barcode** buttons of [RibbonInsertTab](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-windows-forms-ribbon/ribboninserttab/llms-full.txt), [RibbonChartLayoutTab](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-windows-forms-ribbon/ribbonchartlayouttab/llms-full.txt) for a selected chart and [RibbonFrameLayoutTab](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-windows-forms-ribbon/ribbonframelayouttab/llms-full.txt) for the position, text wrapping and size of a selected frame. What their buttons do is shown in [Charts](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/charts-barcodes/#charts) and [Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/charts-barcodes/#barcodes) on the Charts and Barcodes page of the Document Editor section.

A form of your own needs no more than the tabs it uses. In the blog article [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/), a .NET application has a ribbon with only the **Insert** and the **Chart Layout** tab; once the chart package is installed, both tabs recognize the chart control and enable their chart commands:

![A Windows Forms application with a ribbon of two tabs, Insert and Chart Layout, where the Minor Gridlines menu of the X-Axis group shows its color palette above a selected 3-D area chart.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/chart-layout-tab-form.e70a10c4.webp)

The TX Words sample shows these tabs as contextual tabs, which appear only while a chart or a frame is selected. [Built-in Ribbon Tabs](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/ribbon/#show-tabs-only-in-context) shows how to do this, and [Visual Studio Designer Integration](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/integration/designer/llms-full.txt) how to add the tabs in the designer. Without a ribbon, [ChartLayoutDialog](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/chartlayoutdialog-method/llms-full.txt) and [BarcodeLayoutDialog](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/barcodelayoutdialog-method/llms-full.txt) open dialog boxes for the layout of the selected object.

### Create Charts and Barcodes in Code

Your code creates the control, wraps it in its frame and adds the frame to `Charts` or `Barcodes`. A chart control needs at least one chart area and one series before it is wrapped. The code is described on other pages:

| To | Read |
|---|---|
| Insert a chart bound to a `DataTable` | [Add Charts](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/charts-barcodes/#add-charts) in Document Processing |
| Fill the named charts of a loaded document with new data | [Fill the Charts of a Template With Data](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/charts-barcodes/#fill-the-charts-of-a-template-with-data) |
| Insert a QR code or a linear barcode | [Insert a QR Code](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/charts-barcodes/#insert-a-qr-code) and [Insert a Barcode With Text](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/charts-barcodes/#insert-a-barcode-with-text) |
| Change the chart or barcode the user has selected | [Charts and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/charts-barcodes/llms-full.txt) in the Document Editor section |
| Fill charts and barcodes of a template in a mail merge | [Images and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/images-barcodes/llms-full.txt) |

The Charts sample of TX Text Control inserts a chart this way and lets the user change it in a property grid:

![A Windows Forms sample with a column chart in the document and a panel at the right with the chart name points and a property grid of the chart's appearance.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/chart-frame-properties.2882915b.webp)

The `TXBarcodeControl` is not placed on the form: it lives inside the frame. The events [ChartCreated](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/chartcreated-event/llms-full.txt) and [BarcodeCreated](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/barcodecreated-event/llms-full.txt) of the `TextControl` tell your code when a chart or barcode arrives through the clipboard or a loaded document; they don't occur for objects your code adds with `Add`.

### Create a Barcode as SVG With TXBarcodeCore

[TXBarcodeCore](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/llms-full.txt), introduced in version 33.0, is a barcode without a control. It has the type, text and appearance properties of `TXBarcodeControl` and returns the barcode as an SVG string, for example for a web page, an email or an image file. A `BarcodeFrame` takes a `TXBarcodeControl`, as the reference of its [constructor](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-datavisualization/barcodeframe/constructor/llms-full.txt) states, so a barcode that users should edit in the document is inserted as in the previous section. The SVG of a `TXBarcodeCore` goes into a document as an image:

```csharp
using System;
using System.Drawing;
using System.IO;
using TXTextControl.Barcode;

private void insertSvgBarcodeButton_Click(object sender, EventArgs e)
{
    const string orderNumber = "ORD-2025-0042";

    // Initialize the new instance before using it
    TXBarcodeCore barcode = new TXBarcodeCore();
    barcode.Create();
    barcode.BarcodeType = BarcodeType.Code128;
    barcode.UpperTextLength = orderNumber.Length;
    barcode.Text = orderNumber;

    // The barcode as an SVG image
    string svg = barcode.GetSVG(new Size(4320, 1080));
    File.WriteAllText("order-barcode.svg", svg);

    // 8 is the import filter for SVG
    textControl1.Images.Add(new TXTextControl.Image("order-barcode.svg", 8), -1);
}
```

The code works as follows:

- [Create](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/create-method/llms-full.txt) initializes the object and must be called before any other member.
- [BarcodeType](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/barcodetype-property/llms-full.txt) is set first, because [UpperTextLength](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/uppertextlength-property/llms-full.txt), the maximum number of characters, and [Text](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/text-property/llms-full.txt) throw an `ArgumentException` when the value isn't valid for the type.
- [GetSVG](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/getsvg-method/llms-full.txt) returns the SVG in the given size, which also becomes the [Size](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/size-property/llms-full.txt) of the object.
- The image is inserted inline at the input position, as [Images, Text Frames, and Shapes](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/images-shapes/#insert-an-image) describes. It is an image in the document, not a barcode that the barcode tabs of the ribbon can change.

Before you set `Text` from user input, the static [IsTextValid](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/istextvalid-method/llms-full.txt) tells whether a text is valid for a barcode type and returns the error message if not. [GetDefaultText](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/getdefaulttext-method/llms-full.txt) returns a valid sample text, and [GetMinimumTextLength](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/getminimumtextlength-method/llms-full.txt) and [GetMaximumTextLength](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/getmaximumtextlength-method/llms-full.txt) the shortest and longest text of a type. [Save](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/save-method/llms-full.txt) writes the settings of the barcode to a file, a `Stream`, a `TextWriter` or an `XmlWriter`, and [Load](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-barcode/txbarcodecore/load-method/llms-full.txt) reads them into a `TXBarcodeCore` again.

Shapes have a counterpart without a control as well, `TXDrawingCore`, described in [Render Shapes as SVG With TXDrawingCore](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/images-shapes/#render-shapes-as-svg-with-txdrawingcore).

### Next Steps

- [Charts and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/charts-barcodes/llms-full.txt): charts and barcodes from the user's side of the editor.
- [Charts and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/charts-barcodes/llms-full.txt) in Document Processing: the same objects in documents created with `ServerTextControl`.
- [Images and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/images-barcodes/llms-full.txt): merge data into barcodes and charts of a template.
- The blog article [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/): the chart package for .NET with screenshots.

---

## Nearby

- **Previous:** [Integrating TX Spell .NET for Windows Forms](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/integration/tx-spell/llms-full.txt)
- **Next:** [High DPI and Display Scaling](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/integration/dpi-scaling/llms-full.txt)
