简体   繁体   English

使用来自 MSSQL 的实时数据和 node.js 网络服务器可视化图表

[英]Visualization of charts using real time data from MSSQL with node.js webserver

I want to extend my IoT project in order to visualize my incoming IoT data in real time.我想扩展我的 IoT 项目,以便实时可视化传入的 IoT 数据。

What I have done so far:到目前为止我做了什么:

Web server based on hapi.js connected to SQL-Server via Node.js.基于 hapi.js 的 Web 服务器通过 Node.js 连接到 SQL-Server。 The server listens within the network and is able to receive API data pushed via HTTP and store it in a MS SQL database.服务器在网络内监听,并能够接收通过 HTTP 推送的 API 数据并将其存储在 MS SQL 数据库中。 Currently, the data is displayed via an HTML page using a HTML template engine (handlebars).目前,使用 HTML 模板引擎(车把)通过 HTML 页面显示数据。

What I want to extend:我要扩展的内容:

The incoming IoT data should be displayed in a chart via a HTML page.传入的 IoT 数据应通过 HTML 页面显示在图表中。 Preferably in real time.最好是实时的。

I would like to use chart.js or an equivalent JavaScript library.我想使用 chart.js 或等效的 JavaScript 库。

What is the Issue:问题是什么:

I am not sure if my plans can be realized with JavaScript (Node.js) only.我不确定我的计划是否只能通过 JavaScript (Node.js) 来实现。 If yes, can I use handlebars to templating the data in the charts?如果是,我可以使用把手来模板化图表中的数据吗?

How should I start?我应该如何开始?

Chart.js will work fine for your use case. Chart.js 适用于您的用例。 You can use chart update capabilities to add/remove datapoints.您可以使用图表更新功能来添加/删除数据点。 If you want a nice package for doing this, along with some configuration options, you can use chartjs-plugin-streaming .如果您想要一个不错的 package 来执行此操作,以及一些配置选项,您可以使用chartjs-plugin-streaming

In order to have your chart update in realtime as the user remains on the page, it is not enough to use Handlebar templates.为了让您的图表在用户停留在页面上时实时更新,仅使用 Handlebar 模板是不够的。 You should build an API endpoint on your node server that returns the latest data.您应该在返回最新数据的节点服务器上构建 API 端点。

It sounds like you already know how to create routes in hapi.js .听起来您已经知道如何在hapi.js中创建路由。 Look into fetch or similar in order to send a request to your route from the client.查看fetch或类似内容,以便从客户端向您的路由发送请求。 The response will contain latest data and the client will put the new data into the chart.响应将包含最新数据,客户端会将新数据放入图表中。

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

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