繁体   English   中英

将值从我的 Json (Node.js + Express) 传递到我的最终应用程序

[英]Pass values from my Json (Node.js + Express) to my final app

我正在尝试基于此https://www.patrick-wied.at/static/heatmapjs/构建数据中心平面图热图,并从我拥有的一些物理传感器中提取数据。

我在后端(NodeJS + Express)和 HTML/CSS 方面有业余经验,目前我能够成功:

1- 使用 Python 从传感器中检索数据 2- 将该数据保存到 SQLite 数据库中 3- 使用 nodejs+express 连接到该数据库并制作一个工作路由器,该路由器显示 Z466DEEC76ECDF25FCA6D38 中的传感器值(在:分配的 7 路由 D1F6 中) 1,传感器2和时间)

现在,我有一个工作 API 但我的问题是热图与 HTML 文件上的某些变量(ej:点 1:20.4 和点 2:20.6)的值一起工作,该文件与 ZDE9B9ED7808D7E919EFFEEFFEEFFEEFFEEFFEE 集成。

如何将此值从后端传递到 html 页面以将值分配给这些点? 我没有任何将后端与前端集成的知识,因此欢迎提出任何建议。 谢谢!

在没有看到您的代码或不知道您的确切实现的情况下,也许这可以让您大致了解如何使其工作:

// server-side

app.get('/sensorData', (req, res, next) => {
  // DB code to retrieve all sensor data, I assume you have this implemented somehow already and are returning the data as json at some endpoint
  SensorData.getAllSensorData((data) => {
    res.json(data);
  });
});

// client-side

fetch('/sensorData')
  .then(response => response.json())
  .then(sensorData => {
    const dataPoints = sensorData.map(dataPoint => {
      return {
        x: datapoint.x, // or whatever you've named the x-value
        y: datapoint.y,
        value: // whatever the heatmap value is
      };
    });
    heatmapInstance.addData(dataPoints);
  });

暂无
暂无

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

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