How do I automatically update a chart when a table gets a new record?
-
03-03-2021 - |
Frage
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).
Lösung
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.
- Add a
Connection
to your form, set it up so it connects to your database. - Set the
connection
active
property totrue
- Add a Query to your form, set the connection to
connection1
- Set the
sql
property toSELECT (count(*) / b.totalcount) as percentage, b.totalcount FROM table1 a CROSS JOIN (select count(*) as totalcount from table1) b GROUP BY a.color
- Set the
active
property totrue
- Drop a
datasource
on the form, set itsdataset
toquery1
- Drop a DBChart on the form, set its
datasource
todatasource1
- Fiddle with the DBChart to make it display a piechart.