DmitrMakeev commited on
Commit
7b017ad
·
verified ·
1 Parent(s): 0087970

Update online.html

Browse files
Files changed (1) hide show
  1. online.html +11 -6
online.html CHANGED
@@ -610,7 +610,7 @@ document.getElementById("but_sliv").addEventListener("click", function() {
610
  }
611
 
612
  function updateDataHistory(data) {
613
- // Добавляем новые значения
614
  dataHistory.labels.push(dataHistory.labels.length);
615
  dataHistory.dates.push(data.date);
616
  dataHistory.times.push(data.time);
@@ -621,7 +621,7 @@ document.getElementById("but_sliv").addEventListener("click", function() {
621
  dataHistory.hDm.push(parseFloat(data.hDm) || 0);
622
  dataHistory.sVen.push(parseFloat(data.sVen) || 0);
623
 
624
- // Обрезаем массив, если он превышает maxPoints
625
  while (dataHistory.labels.length > maxPoints) {
626
  dataHistory.labels.shift();
627
  dataHistory.dates.shift();
@@ -633,6 +633,9 @@ document.getElementById("but_sliv").addEventListener("click", function() {
633
  dataHistory.hDm.shift();
634
  dataHistory.sVen.shift();
635
  }
 
 
 
636
  }
637
 
638
  function updateChart() {
@@ -678,10 +681,10 @@ document.getElementById("but_sliv").addEventListener("click", function() {
678
  xhr.send();
679
  }
680
 
681
- // Обработчик изменения периода в выпадающем списке
682
  document.getElementById("periodSelect").addEventListener("change", function() {
683
- maxPoints = parseInt(this.value); // Преобразуем строку в число
684
- // Обрезаем существующие данные до нового лимита
685
  while (dataHistory.labels.length > maxPoints) {
686
  dataHistory.labels.shift();
687
  dataHistory.dates.shift();
@@ -693,7 +696,9 @@ document.getElementById("but_sliv").addEventListener("click", function() {
693
  dataHistory.hDm.shift();
694
  dataHistory.sVen.shift();
695
  }
696
- updateChart(); // Перерисовываем график
 
 
697
  });
698
 
699
  // Первый запрос и периодическое обновление
 
610
  }
611
 
612
  function updateDataHistory(data) {
613
+ // Добавляем новые значения в конец
614
  dataHistory.labels.push(dataHistory.labels.length);
615
  dataHistory.dates.push(data.date);
616
  dataHistory.times.push(data.time);
 
621
  dataHistory.hDm.push(parseFloat(data.hDm) || 0);
622
  dataHistory.sVen.push(parseFloat(data.sVen) || 0);
623
 
624
+ // Обрезаем до maxPoints, удаляя старые значения с начала
625
  while (dataHistory.labels.length > maxPoints) {
626
  dataHistory.labels.shift();
627
  dataHistory.dates.shift();
 
633
  dataHistory.hDm.shift();
634
  dataHistory.sVen.shift();
635
  }
636
+
637
+ // Пересчитываем labels как индексы от 0 до maxPoints-1
638
+ dataHistory.labels = Array.from({ length: dataHistory.labels.length }, (_, i) => i);
639
  }
640
 
641
  function updateChart() {
 
681
  xhr.send();
682
  }
683
 
684
+ // Обработчик изменения периода
685
  document.getElementById("periodSelect").addEventListener("change", function() {
686
+ maxPoints = parseInt(this.value);
687
+ // Обрезаем данные до нового лимита
688
  while (dataHistory.labels.length > maxPoints) {
689
  dataHistory.labels.shift();
690
  dataHistory.dates.shift();
 
696
  dataHistory.hDm.shift();
697
  dataHistory.sVen.shift();
698
  }
699
+ // Пересчитываем labels
700
+ dataHistory.labels = Array.from({ length: dataHistory.labels.length }, (_, i) => i);
701
+ updateChart();
702
  });
703
 
704
  // Первый запрос и периодическое обновление