简体   繁体   English

当表格获得新记录时,如何自动更新图表?

[英]How do I automatically update a chart when a table gets a new record?

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. 假设我有一个带有颜色字段(红色/白色/蓝色)的表,并且每次我的应用程序通过TCP / IP接收到一个事件并将新行插入数据库时​​,我都希望有一个数据感知的饼图组件自动更新显示这些颜色的比例。 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). 实际上,我什至不确定在数据库中添加另一行是否会将另一行添加到支持DB的网格(推式,而不是拉式)。

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). 我什至不确定在数据库中添加另一行是否会将另一行添加到DB感知网格(推式,而不是拉式)。

If the dataset is live , adding a row to the dataset will update the grid. 如果数据集是live ,则向数据集添加一行将更新网格。

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. 看,让我们想象一下,我有一个主键是颜色的表-红色/白色/蓝色-每次我的应用程序通过TCP / IP接收事件并将新行插入数据库时​​,我都希望有一个数据感知派图表组件自动更新以显示这些颜色的比率。

  1. Add a Connection to your form, set it up so it connects to your database. 将一个Connection添加到您的表单,进行设置以使其连接到您的数据库。
  2. Set the connection active property to true connection active属性设置为true
  3. Add a Query to your form, set the connection to connection1 将查询添加到您的窗体,将连接设置为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 sql属性设置为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 active属性设置为true
  6. Drop a datasource on the form, set its dataset to query1 在表单上放置一个datasource ,将其dataset设置为query1
  7. Drop a DBChart on the form, set its datasource to datasource1 在表单上放置一个DBChart,将其datasource datasource1设置为datasource1
  8. Fiddle with the DBChart to make it display a piechart. 用DBChart进行修饰,使其显示一个饼图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM