The RAD Studio, C++ Builder 11 and C++ Builder CE Community Editions have a lot of amazing visual and nonvisual components that you can use in your modern applications for Windows and mobile. One of these is the free chart component for the VCL and FMX frameworks called TeeChart (TChart). TChart comes with RAD Studio including RAD Studio 10.x,11.x and the CE versions.
Table of Contents
How To Install and Use TeeChart (TChart) in C++ Builder CE?
When you install RAD Studio on the second page of the “platforms” choices are some optional modules and components. One of those is “TeeChart Standard”. This is the free version of TChart which you can use in your applications.
If you want more detailed professional charts in your applications, there is also TeeChart Pro by Steema. The TeeChart Pro charting component library offers hundreds of Graph styles in 2D and 3D for data visualization, 56 mathematical, statistical, and financial functions for you to choose from together with an unlimited number of axes and 30 Palette components. Please visit their official Steema web page for more details.
How To Develop Apps With TeeChart (TChart) in C++?
If you installed TChart in C++ Builder, you can use this component in your VCL or FMX applications. To do this:
- Create a New C++ Builder VCL Windows Application in RAD Studio
- Go to Palette window, there is TChart component (under the TeeChart Lite category) to visualize many kind of chart graphics. Drag it on to form, or If you have a specific area like a panel, rectangle or a tab drag it on to this area. You can move, resize or align it by selecting Align->Client selection, you can also set its margins.
Now you can modify its default settings and you can add your custom charts, Pie, Bars, y=f(x) series, etc.
How To Draw y = f(x) Series With TeeChart (TChart) in C++?
- Double click to TChart to create your own Chart series.
- Press “Add…” Button in Editing Chart Window, this will bring you to the Series Gallery as shown below.
- Select Functions tab and select y=f(x) series,
- Press OK, and Close
- When you are in form designer mode, be sure that there is Series1 in the Structure panel as below,
- Now you have a y =f(x) graph, add a Button (TButton)
- Double Click to your button (i.e. Button1)
- When user clicks this button we can clear and add series in this button click like so:
1 2 3 4 5 6 7 8 |
Series1->Clear(); Series1->Add( 0.0, 55.0, clTeeColor ); Series1->Add( 10.0, 72.0, clTeeColor ); Series1->Add( 30.0, 95.0, clTeeColor ); Series1->Add( 40.0, 123.0, clTeeColor ); |
How To Draw Bar Series With TeeChart (TChart) in C++?
If you want you can add a new Bar Chart,
- Double click to TChart to create your own Chart series.
- Press “Add…” Button in Editing Chart Window, this will bring you Series Gallery as below,
- In Series tab, select Bar Series,(i.e. this will be named as Series2)
- Press OK, and Close
- Add a new Button (TButton), named as Button2
- Double click to this button (i.e Button2)
- When user clicks this button we can clear and add bar series in this button click as below here
1 2 3 4 5 6 7 8 |
Series2->Clear(); Series2->Add( 88.0, "Jan", clTeeColor ); Series2->Add( 72.0, "Feb", clTeeColor ); Series2->Add( 95.0, "Mar", clTeeColor ); Series2->Add( 123.0, "Apr", clTeeColor ); |
that’s all! Now you can press F9 to run you application.
Is There A Full Example of how to use TeeChart (TChart) in C++?
Here is a full example that has Two TCharts (Chart1, Chart2), first chart has Series1 which is y=fx series, the second chart has Series2 has bar series, and there are two buttons (Button1, Button2), if you click both of them, you can modify your code like we show below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <fmx.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.fmx" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Series1->Clear(); Series1->Add( 0.0, 55.0, clTeeColor ); Series1->Add( 10.0, 72.0, clTeeColor ); Series1->Add( 30.0, 95.0, clTeeColor ); Series1->Add( 40.0, 123.0, clTeeColor ); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { Series2->Clear(); Series2->Add( 88.0, "Jan", clTeeColor ); Series2->Add( 72.0, "Feb", clTeeColor ); Series2->Add( 95.0, "Mar", clTeeColor ); Series2->Add( 123.0, "Apr", clTeeColor ); } |
Here is a simple example of our design and its outputs when we click Button1 and Button2,
Note that, you can create a for loop for a specific function, or you can read data and set them here as above too. You can also visually bind database tables directly into teecharts, you don’t need to code as above.
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.
There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise version.
Design. Code. Compile. Deploy.
Start Free Trial
Free C++Builder Community Edition