Site icon Python GUI

Tutorial: Generate Python Dummy Data And Plot It To Enterprise-Grade Delphi TChart

blogbanner3 25

In this tutorial, we will learn about how to do data visualizations using Delphi’s TChart or TeeChart.

TChart is the 100% Native Data-Aware Charting Component Library for Delphi and C++ Builder (v5 and later) and all RAD Studio versions.

 

1. Generate the Dummy Data with Python

To create dummy data in Python, you can use pandas or the Faker library.

Here is the easiest way to create dummy data using pandas, and export them to CSV:

[crayon-6605ffd7619f1690110596/]

By default, it will create 30 rows with columns called A, B, C, and D and the index alpha-numeric. Run the code above in your favorite Python IDE (for me, it’s PyScripter, because it’s lightweight), you will get the following result:

The result:

Or you can try Faker, to generate more sophisticated data, with this code:

[crayon-6605ffd7619f9957521536/]

The code above will generate dummy data with various Python data types and 1000 rows of observations in total:

 

2. How can we use TChart?

The TChart component is the basic building block for ‘non-database-aware’ Charts.

First, start an empty VCL app, by navigating to File -> New -> Windows VCL Application – Delphi:

Select the TChart component from the Delphi palette and simply drag it onto your form to include a Chart in your application:

This is how TChart will look like in your empty VCL:

You can edit the chart by double-click the TChart component. For example, you can add new data series, by navigating to Series > Add > Choose the chart as you need:

You can easily create enterprise-grade plots using the Import option or TDataImport class. Using this functionality, you can seamlessly plot any data from any sources, like .CSV files, SQLs, JSON, the dataset from URLs, and many more. Unfortunately, this feature only available in TChart Pro, so I strongly recommend you to try TChart Pro which 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. Visit this link, this tutorial, or this video for more information.

So, for this tutorial, we need to input our data, and create our data series manually. In Series, go to Data Source by double-clicking the Series, and change Random to Manual.

Now, you can input our dummy data generated by Pandas. In this example, I input 4 data series with 10 rows of observations:

This is how our data visualized in TChart’s Bar Chart:

This is how our data visualized in TChart’s Line Chart:

Congratulations! You have learn how to visualize Python’s data using Delphi’s TChart!

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi.

Exit mobile version