使用Php / SQL在Highcharts / Highstocks上添加了一个新系列

时间:2018-02-22 09:54:26

标签: php sql highcharts

大家早上好! 所以现在我有一个年终项目要实现,我的客户希望有一个带图形的网站。然后我使用了Highcharts图形之一。在我的数据库中,名为“didatec”,对于表“获取”,我的列有“时间”,“度”和“分贝”。我开始制作带有日期(横坐标)和温度(纵坐标)的图表,一切正常! 现在,当我添加我的文件“values.php”. $row[' decibel'].在我的文件“data.js”中,图表将我的恢复数据放在任何方向,同时我的分贝也必须订购(如温度)。

在此图像上,图表仅适用于温度和日期。我们现在需要的只是分贝......

只有温度和日期的图表
The graph with just the temperature and date

数据库
Database

First part of the data. js file with decibels

Second part of the data. js file with decibels

以任何方式使用数据的图表(添加分贝)
Graph with data any way (add decibels)

在“值.php”页面上的php中检索数据。首先是分贝之后的日期和时间(时间戳),第二个度数 Data retrieved in php on the "values. php"page. First the date and time (timestamp), second the degrees, after decibels

The code for "values. php"

我允许自己重新启动这个主题,这个主题完全相同,但在图表上刷新数据。我测试了setInterval,但它完全刷新了图形并使其消失。我还看到有chart.redraw和setdata。如果你有一个解决方案,我会受到重创!谢谢 ! :)

1 个答案:

答案 0 :(得分:1)

解析数据的方法存在问题。例如:

> var data = '2018-02-06 00:00:00/15/15/2018-02-07 00:00:00/12/3'.split('/'); 
> ["2018-02-06 00:00:00", "15", "15", "2018-02-07 00:00:00", "12", "3"]

现在你应该像这样循环点:

for (var i = 0; i < data.length; i += 3) {
  time.push(data[i]);
  degres.push(parseFloat(data[i + 1]));
  decibels.push(parseFloat(data[i + 2]));
}

当然,如果您决定添加更多数据集,请将i+=3更改为i+=4等。