DmitrMakeev commited on
Commit
474ab08
·
verified ·
1 Parent(s): a138e4b

Update registrations_period.html

Browse files
Files changed (1) hide show
  1. registrations_period.html +12 -86
registrations_period.html CHANGED
@@ -49,7 +49,7 @@
49
  border-color: #4CAF50;
50
  box-shadow: 0 0 5px rgba(76, 175, 80, 0.5);
51
  }
52
- .chart-container {
53
  margin-top: 20px;
54
  display: flex;
55
  justify-content: center;
@@ -77,61 +77,34 @@
77
  <!-- Кнопка для получения данных -->
78
  <button onclick="fetchData()">Получить данные</button>
79
 
80
- <!-- Контейнер для столбчатого графика -->
81
- <div class="chart-container">
82
- <canvas id="barChart" width="400" height="200"></canvas>
83
- </div>
84
-
85
- <!-- Контейнер для линейного графика -->
86
- <div class="chart-container">
87
- <canvas id="lineChart" width="400" height="200"></canvas>
88
  </div>
89
 
90
  <script>
91
- let barChart; // Переменная для хранения столбчатого графика
92
- let lineChart; // Переменная для хранения линейного графика
93
-
94
- // Цвета для линий (10 цветов)
95
- const lineColors = [
96
- '#FF6384', // Красный
97
- '#36A2EB', // Синий
98
- '#FFCE56', // Жёлтый
99
- '#4BC0C0', // Бирюзовый
100
- '#9966FF', // Фиолетовый
101
- '#FF9F40', // Оранжевый
102
- '#C9CBCF', // Серый
103
- '#00CC99', // Зелёный
104
- '#FF99CC', // Розовый
105
- '#6666FF' // Голубой
106
- ];
107
-
108
- // Функция для запроса данных и обновления графиков
109
  function fetchData() {
110
  // Получаем выбранные даты
111
  const startDate = document.getElementById('startDate').value;
112
  const endDate = document.getElementById('endDate').value;
113
-
114
  // Проверяем, что обе даты выбраны
115
  if (!startDate || !endDate) {
116
  alert("Пожалуйста, выберите обе даты.");
117
  return;
118
  }
119
-
120
  // Запрос данных с сервера
121
  fetch(`/registrations_period?start_date=${startDate}&end_date=${endDate}`)
122
  .then(response => response.json())
123
  .then(data => {
124
- // Если графики уже существуют, уничтожаем их
125
- if (barChart) {
126
- barChart.destroy();
127
  }
128
- if (lineChart) {
129
- lineChart.destroy();
130
- }
131
-
132
- // Создание столбчатого графика
133
- const barCtx = document.getElementById('barChart').getContext('2d');
134
- barChart = new Chart(barCtx, {
135
  type: 'bar',
136
  data: {
137
  labels: data.labels,
@@ -174,58 +147,11 @@
174
  maintainAspectRatio: false
175
  }
176
  });
177
-
178
- // Создание линейного графика
179
- const lineCtx = document.getElementById('lineChart').getContext('2d');
180
- lineChart = new Chart(lineCtx, {
181
- type: 'line',
182
- data: {
183
- labels: data.dates, // Дни периода
184
- datasets: data.daily_data.map((dataset, index) => ({
185
- label: dataset.label, // Метка
186
- data: dataset.data, // Данные за каждый день
187
- borderColor: lineColors[index % lineColors.length], // Цвет линии
188
- borderWidth: 2,
189
- fill: false
190
- }))
191
- },
192
- options: {
193
- scales: {
194
- y: {
195
- beginAtZero: true,
196
- grid: {
197
- color: '#f0f0f0'
198
- },
199
- ticks: {
200
- color: '#333'
201
- }
202
- },
203
- x: {
204
- grid: {
205
- color: '#f0f0f0'
206
- },
207
- ticks: {
208
- color: '#333'
209
- }
210
- }
211
- },
212
- plugins: {
213
- legend: {
214
- labels: {
215
- color: '#333'
216
- }
217
- }
218
- },
219
- responsive: true,
220
- maintainAspectRatio: false
221
- }
222
- });
223
  })
224
  .catch(error => {
225
  console.error('Ошибка при получении данных:', error);
226
  });
227
  }
228
-
229
  // Устанавливаем сегодняшнюю дату по умолчанию и загружаем данные
230
  window.onload = function() {
231
  const today = new Date().toISOString().split('T')[0];
 
49
  border-color: #4CAF50;
50
  box-shadow: 0 0 5px rgba(76, 175, 80, 0.5);
51
  }
52
+ #chartContainer {
53
  margin-top: 20px;
54
  display: flex;
55
  justify-content: center;
 
77
  <!-- Кнопка для получения данных -->
78
  <button onclick="fetchData()">Получить данные</button>
79
 
80
+ <!-- Контейнер для графика -->
81
+ <div id="chartContainer">
82
+ <canvas id="registrationsChart" width="400" height="200"></canvas>
 
 
 
 
 
83
  </div>
84
 
85
  <script>
86
+ let myChart; // Переменная для хранения графика
87
+ // Функция для запроса данных и обновления графика
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  function fetchData() {
89
  // Получаем выбранные даты
90
  const startDate = document.getElementById('startDate').value;
91
  const endDate = document.getElementById('endDate').value;
 
92
  // Проверяем, что обе даты выбраны
93
  if (!startDate || !endDate) {
94
  alert("Пожалуйста, выберите обе даты.");
95
  return;
96
  }
 
97
  // Запрос данных с сервера
98
  fetch(`/registrations_period?start_date=${startDate}&end_date=${endDate}`)
99
  .then(response => response.json())
100
  .then(data => {
101
+ // Если график уже существует, уничтожаем его
102
+ if (myChart) {
103
+ myChart.destroy();
104
  }
105
+ // Создание нового графика
106
+ const ctx = document.getElementById('registrationsChart').getContext('2d');
107
+ myChart = new Chart(ctx, {
 
 
 
 
108
  type: 'bar',
109
  data: {
110
  labels: data.labels,
 
147
  maintainAspectRatio: false
148
  }
149
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  })
151
  .catch(error => {
152
  console.error('Ошибка при получении данных:', error);
153
  });
154
  }
 
155
  // Устанавливаем сегодняшнюю дату по умолчанию и загружаем данные
156
  window.onload = function() {
157
  const today = new Date().toISOString().split('T')[0];