0

Suppose I have a table with a colour field — red/white/blue — and every time my app receives an event over TCP/IP and inserts a new row into the database, I want a data-aware pie chart component to auto-update showing the ratio of those colours. How can I do that?

I've seen examples of data-aware components, but they just show the value of each row of a table (I haven't gotten too far yet). In fact, I am not even sure that adding another row in the database will add another row to the DB-aware grid (push, as opposed to pull).

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • 1
    Which database and which kind of data aware controls? – Jens Mühlenhoff Nov 17 '11 at 13:57
  • 3
    Delphi already comes with [data-aware controls](http://docwiki.embarcadero.com/RADStudio/XE2/en/Data_Controls). For charts, there's TDBChart. – Ondrej Kelle Nov 17 '11 at 14:03
  • 1
    Did you look at the tutorials on the wiki, available at the same link as TOndrej posted, or click here: http://docwiki.embarcadero.com/RADStudio/en/Tutorial:_Using_dbExpress_to_View_and_Update_Databases_in_an_Application – Warren P Nov 17 '11 at 14:13
  • 2
    Mawg; FYI - The edits by Rob vastly improve the quality and readability of your answer. Note that all references to pizza pies are off topic on Stack overflow. Keep it pro, and keep it focused! – Warren P Nov 17 '11 at 16:59
  • +1 to all. TMS & mySql. Apologies for levity. Thanks for the tutorial link. – Mawg says reinstate Monica Nov 17 '11 at 23:20
  • @warrenp I thought that in the context of pie charts pizza references are surprisingly on topic :-) – Johan Nov 18 '11 at 05:37

1 Answers1

3

I am not even sure that adding another row in the database will add another row to the DB aware grid (push, as opposed to pull).

If the dataset is live, adding a row to the dataset will update the grid.

Look, let's just imagine that I have a table who's primary key is a colour - red/white/blue - and every time my app receives an event over TCP/IP and inserts a new row into the database I want a data-aware pie chart component to auto-update showing the ratio of those colours.

  1. Add a Connection to your form, set it up so it connects to your database.
  2. Set the connection active property to true
  3. Add a Query to your form, set the connection to connection1
  4. Set the sql property to SELECT (count(*) / b.totalcount) as percentage, b.totalcount FROM table1 a CROSS JOIN (select count(*) as totalcount from table1) b GROUP BY a.color
  5. Set the active property to true
  6. Drop a datasource on the form, set its dataset to query1
  7. Drop a DBChart on the form, set its datasource to datasource1
  8. Fiddle with the DBChart to make it display a piechart.
Johan
  • 74,508
  • 24
  • 191
  • 319
  • +1 and the answer. Thanks for such a clear and helpful answer. I guessed that there ought to be a "live" option, otherwise the value of such components would be greatly diminished. And it's good to see that I can use the result of an SQL query in a DB component, not just the raw data. – Mawg says reinstate Monica Nov 17 '11 at 23:23
  • For my next step, I will try to have a grid where each row of the grid is built up of several queries. But first I will read the tutorials and write some sample code and play around to get a feel for it. Thanks again for your help. – Mawg says reinstate Monica Nov 17 '11 at 23:25