DmitrMakeev commited on
Commit
a51e39d
·
verified ·
1 Parent(s): 7b09368

Update online.html

Browse files
Files changed (1) hide show
  1. online.html +24 -20
online.html CHANGED
@@ -469,7 +469,8 @@ document.getElementById("but_sliv").addEventListener("click", function() {
469
  // Объект для хранения истории данных (до 60 значений)
470
  let dataHistory = {
471
  labels: [], // Индексы для оси X
472
- times: [], // Отдельный массив для времени (только для карточек)
 
473
  ph: [],
474
  ec: [],
475
  tS: [],
@@ -497,8 +498,8 @@ document.getElementById("but_sliv").addEventListener("click", function() {
497
  name: "pH",
498
  mode: "lines",
499
  line: { color: "blue" },
500
- customdata: dataHistory.times, // Привязываем время для карточек
501
- hovertemplate: "<b>pH: %{y}</b><br>Время: %{customdata}<extra></extra>",
502
  hoverlabel: { bgcolor: "blue", font: { color: "white" } }
503
  },
504
  {
@@ -507,8 +508,8 @@ document.getElementById("but_sliv").addEventListener("click", function() {
507
  name: "EC",
508
  mode: "lines",
509
  line: { color: "green" },
510
- customdata: dataHistory.times,
511
- hovertemplate: "<b>EC: %{y}</b><br>Время: %{customdata}<extra></extra>",
512
  hoverlabel: { bgcolor: "green", font: { color: "white" } }
513
  },
514
  {
@@ -517,8 +518,8 @@ document.getElementById("but_sliv").addEventListener("click", function() {
517
  name: "Т. раствора",
518
  mode: "lines",
519
  line: { color: "red" },
520
- customdata: dataHistory.times,
521
- hovertemplate: "<b>Т. раствора: %{y}</b><br>Время: %{customdata}<extra></extra>",
522
  hoverlabel: { bgcolor: "red", font: { color: "white" } }
523
  },
524
  {
@@ -527,8 +528,8 @@ document.getElementById("but_sliv").addEventListener("click", function() {
527
  name: "Т. воздуха",
528
  mode: "lines",
529
  line: { color: "orange" },
530
- customdata: dataHistory.times,
531
- hovertemplate: "<b>Т. воздуха: %{y}</b><br>Время: %{customdata}<extra></extra>",
532
  hoverlabel: { bgcolor: "orange", font: { color: "white" } }
533
  },
534
  {
@@ -537,8 +538,8 @@ document.getElementById("but_sliv").addEventListener("click", function() {
537
  name: "Вл. воздуха",
538
  mode: "lines",
539
  line: { color: "purple" },
540
- customdata: dataHistory.times,
541
- hovertemplate: "<b>Вл. воздуха: %{y}</b><br>Время: %{customdata}<extra></extra>",
542
  hoverlabel: { bgcolor: "purple", font: { color: "white" } }
543
  },
544
  {
@@ -547,8 +548,8 @@ document.getElementById("but_sliv").addEventListener("click", function() {
547
  name: "Об. вентилятора",
548
  mode: "lines",
549
  line: { color: "brown" },
550
- customdata: dataHistory.times,
551
- hovertemplate: "<b>Об. вентилятора: %{y}</b><br>Время: %{customdata}<extra></extra>",
552
  hoverlabel: { bgcolor: "brown", font: { color: "white" } }
553
  }
554
  ];
@@ -586,7 +587,8 @@ document.getElementById("but_sliv").addEventListener("click", function() {
586
  function updateDataHistory(data) {
587
  // Добавляем новые значения
588
  dataHistory.labels.push(dataHistory.labels.length); // Просто индексы для оси X
589
- dataHistory.times.push(new Date().toLocaleTimeString()); // Только время для карточек
 
590
  dataHistory.ph.push(parseFloat(data.ph) || 0);
591
  dataHistory.ec.push(parseFloat(data.ec) || 0);
592
  dataHistory.tS.push(parseFloat(data.tS) || 0);
@@ -597,6 +599,7 @@ document.getElementById("but_sliv").addEventListener("click", function() {
597
  // Если больше 60 значений, удал��ем первое
598
  if (dataHistory.labels.length > 60) {
599
  dataHistory.labels.shift();
 
600
  dataHistory.times.shift();
601
  dataHistory.ph.shift();
602
  dataHistory.ec.shift();
@@ -609,6 +612,7 @@ document.getElementById("but_sliv").addEventListener("click", function() {
609
 
610
  function updateChart() {
611
  // Обновляем данные графика
 
612
  Plotly.update("parametersChart", {
613
  x: [
614
  dataHistory.labels,
@@ -627,12 +631,12 @@ document.getElementById("but_sliv").addEventListener("click", function() {
627
  dataHistory.sVen
628
  ],
629
  customdata: [
630
- dataHistory.times,
631
- dataHistory.times,
632
- dataHistory.times,
633
- dataHistory.times,
634
- dataHistory.times,
635
- dataHistory.times
636
  ]
637
  });
638
  }
 
469
  // Объект для хранения истории данных (до 60 значений)
470
  let dataHistory = {
471
  labels: [], // Индексы для оси X
472
+ dates: [], // Даты с сервера
473
+ times: [], // Время с сервера
474
  ph: [],
475
  ec: [],
476
  tS: [],
 
498
  name: "pH",
499
  mode: "lines",
500
  line: { color: "blue" },
501
+ customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
502
+ hovertemplate: "<b>pH: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
503
  hoverlabel: { bgcolor: "blue", font: { color: "white" } }
504
  },
505
  {
 
508
  name: "EC",
509
  mode: "lines",
510
  line: { color: "green" },
511
+ customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
512
+ hovertemplate: "<b>EC: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
513
  hoverlabel: { bgcolor: "green", font: { color: "white" } }
514
  },
515
  {
 
518
  name: "Т. раствора",
519
  mode: "lines",
520
  line: { color: "red" },
521
+ customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
522
+ hovertemplate: "<b>Т. раствора: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
523
  hoverlabel: { bgcolor: "red", font: { color: "white" } }
524
  },
525
  {
 
528
  name: "Т. воздуха",
529
  mode: "lines",
530
  line: { color: "orange" },
531
+ customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
532
+ hovertemplate: "<b>Т. воздуха: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
533
  hoverlabel: { bgcolor: "orange", font: { color: "white" } }
534
  },
535
  {
 
538
  name: "Вл. воздуха",
539
  mode: "lines",
540
  line: { color: "purple" },
541
+ customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
542
+ hovertemplate: "<b>Вл. воздуха: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
543
  hoverlabel: { bgcolor: "purple", font: { color: "white" } }
544
  },
545
  {
 
548
  name: "Об. вентилятора",
549
  mode: "lines",
550
  line: { color: "brown" },
551
+ customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
552
+ hovertemplate: "<b>Об. вентилятора: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
553
  hoverlabel: { bgcolor: "brown", font: { color: "white" } }
554
  }
555
  ];
 
587
  function updateDataHistory(data) {
588
  // Добавляем новые значения
589
  dataHistory.labels.push(dataHistory.labels.length); // Просто индексы для оси X
590
+ dataHistory.dates.push(data.date); // Дата с сервера
591
+ dataHistory.times.push(data.time); // Время с сервера
592
  dataHistory.ph.push(parseFloat(data.ph) || 0);
593
  dataHistory.ec.push(parseFloat(data.ec) || 0);
594
  dataHistory.tS.push(parseFloat(data.tS) || 0);
 
599
  // Если больше 60 значений, удал��ем первое
600
  if (dataHistory.labels.length > 60) {
601
  dataHistory.labels.shift();
602
+ dataHistory.dates.shift();
603
  dataHistory.times.shift();
604
  dataHistory.ph.shift();
605
  dataHistory.ec.shift();
 
612
 
613
  function updateChart() {
614
  // Обновляем данные графика
615
+ const customdata = dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]);
616
  Plotly.update("parametersChart", {
617
  x: [
618
  dataHistory.labels,
 
631
  dataHistory.sVen
632
  ],
633
  customdata: [
634
+ customdata,
635
+ customdata,
636
+ customdata,
637
+ customdata,
638
+ customdata,
639
+ customdata
640
  ]
641
  });
642
  }