Visiobibliophobia
Visiobibliophobia

Reputation: 63

Using Delphi TChart to display information from a database

I want to create a pie chart in Delphi that will show the user the number of people who play a specific sport.

The following SQL statements gets the information from the database and stores the number of people in a variable. The data type in the database is yes/no, so those who play a specific sport will have a tick and those who don't won't. The sql statement will determine how many people play a specific sport (if there is a tick in the database)

qry.sql.clear;
qry.sql.add('SELECT Count(tennis) AS [NoTennis] FROM [Sports] WHERE Tennis = True');
qry.Open;
iTennis := qry['NoTennis'];   {integer variable}

This repeats for all the other sports, such as swimming, hockey, etc

Afterwards this data must be represented in the pie chart. I have the following code...

Chart1.Series[0].AddXY(iTennis, 1, 'Tennis', clTeeColor);

This also obviously repeats for all the other sports. But instead of displaying my data during run time, it still displays random data about keyboards and motorists, etc. To see what I am talking about click here
(source: asiplease.net)

How do I get TChart to change it's data? Is it the SQL statement or adding the x and y values that is causing the problem?

Upvotes: 2

Views: 6585

Answers (1)

ventiseis
ventiseis

Reputation: 3099

You are showing a pie chart. The chart type is relevant how you add data to the chart. I remember thas AddXy was only for line-based chart. Try

Chart1.Series[0].Add(123, 'Tennis');

See steema documentation.

To clear previously generated values of the series, use

Chart1.Series[0].Clear();

Upvotes: 2

Related Questions