从文本文件生成具有 2 Y 值的图形

发布于 2024-08-31 04:37:30 字数 346 浏览 2 评论 0原文

我重新制作了原来的帖子,因为它的格式非常糟糕。基本上我想要一些关于如何生成带有 2 Y 轴(温度和湿度)的折线图以显示文本文件中的一些信息的建议/提示。它包含在一个名为 tempdata.txt 的文本文件中,我在 JpGrapher 论坛中包含了我的一篇帖子的链接,只是因为它能够清晰地显示代码。

我知道因为这是 JpGraph 问题,所以我不应该在这里发帖,但是这里的社区更加支持和活跃。非常感谢您提前提供的所有帮助!

我的代码

I have remade my original post as it was terribly formatted. Basically I would like some advice / tips on how to generate a line graph with 2 Y Axis (temperature and humidity) to display some information from my text file. It is contained in a textfile called temperaturedata.txt I have included a link to one of my posts from the JpGrapher forum only because it is able to display the code clearly.

I understand that since it is JpGraph problem I shouldn't post here however the community here is a lot more supportive and active. Many thanks for all your help guys in advance!

my code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心的憧憬 2024-09-07 04:37:30

我不认为您有任何理由不应该在这里发布有关 jpgraph 的文章。我也不明白为什么您不应该在此处发布示例代码和数据。

您在其他网站上发布的代码已损坏。检查#42 行。

此外,您通过 $keyval 向 JpGraph 传递一行(特别是最后一行)。 $data 是存储所有数据的位置,尽管格式错误。一个非常快速的修复方法是:

$keyval = array();
$keyval['time'] = array();
$keyval['count'] = array();
$keyval['temperature'] = array();
$keyval['humidity'] = array();

if ($file) {
 while (!feof($file)) {
  $line = trim(fgets($file));
  if (strlen($line)) {
   $fields = explode(":", $line);
   $keyval['time'][]        = $fields[0];
   $keyval['count'][]       = $fields[1];
   $keyval['temperature'][] = $fields[2];
   $keyval['humidity'][]    = $fields[3];
  }
 }

 fclose($file);
}

调换 $data 并将其重命名为 $keyval。 (过去将时间数据保存在 $data[x]['time'] 中,现在将其保存在 $keyval['time'][x] 中。 )我们传递 $keyval['Temperature'],它是一个简单的温度值数组。

I don't see any reason why you shouldn't post here about jpgraph. And I don't see why you shouldn't post your sample code and data here, either.

The code you've posted on the other site is broken. Check line #42.

Furthermore, you're passing JpGraph a single row (specifically, the last row) via $keyval. $data is where all your data is stored, though in a wrong format. A very quick fix was:

$keyval = array();
$keyval['time'] = array();
$keyval['count'] = array();
$keyval['temperature'] = array();
$keyval['humidity'] = array();

if ($file) {
 while (!feof($file)) {
  $line = trim(fgets($file));
  if (strlen($line)) {
   $fields = explode(":", $line);
   $keyval['time'][]        = $fields[0];
   $keyval['count'][]       = $fields[1];
   $keyval['temperature'][] = $fields[2];
   $keyval['humidity'][]    = $fields[3];
  }
 }

 fclose($file);
}

which transposed $data and renamed it $keyval. (Where it used to hold time data in $data[x]['time'], it now holds it in $keyval['time'][x].) And we're passing $keyval['temperature'], which is a simple array of temperature values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文