2

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?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
  • 1
    Don't worry. These are example data shown at design time that are used to help you to configure the chart as you can see the preview. Anyway, you might consider fetching all the statistics at once (in a single query) and use the `TDBChart`. – TLama Aug 23 '15 at 08:56
  • Or maybe better build a structure (class) that holds all the data you will present and a presenter, that setup the chart. Fill the instance with the data and present it. After that it does not matter where you get the data from. First build the presenter and test it. After then fill the instance with the data from the db and present it. – Sir Rufo Aug 23 '15 at 09:03
  • Can you provide a simple example project, using a sample database, we can run "as-is" to reproduce the problem here? Thanks. – Narcís Calvet Aug 27 '15 at 10:13
  • That's a design time snapshot, is it still not working at runtime – Toby Allen Oct 04 '15 at 19:58

1 Answers1

2

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();
ventiseis
  • 3,029
  • 11
  • 32
  • 49