dammmmmmmmm commited on
Commit
4751f7c
·
verified ·
1 Parent(s): 7ba9dfb

Update frontend/dashboard.html

Browse files
Files changed (1) hide show
  1. frontend/dashboard.html +51 -28
frontend/dashboard.html CHANGED
@@ -258,7 +258,7 @@
258
  }
259
  }
260
 
261
- // --- CÁC HÀM HELPER & CHART (GIỮ NGUYÊN LOGIC CŨ) ---
262
  function formatAHT(seconds) {
263
  if (!seconds || isNaN(seconds)) return "00:00";
264
  const m = Math.floor(seconds / 60).toString().padStart(2, '0');
@@ -327,38 +327,61 @@
327
  const retentionData = [65,68,62,70,75,72,78];
328
  const upsellData = [10,12,8,15,14,13,16];
329
 
 
330
  const busCtx = document.getElementById('businessChart').getContext('2d');
331
- if(busChart) busChart.destroy();
332
- busChart = new Chart(busCtx,{
333
- type:'line',
334
- data:{ labels, datasets:[
335
- {label:'Retention (%)', data: retentionData.slice(0,labels.length), borderColor:'#10b981', backgroundColor:'rgba(16,185,129,0.1)', tension:0.4, fill:true, borderWidth:3},
336
- {label:'Upsell (%)', data: upsellData.slice(0,labels.length), borderColor:'#0ea5e9', backgroundColor:'rgba(14,165,233,0.1)', tension:0.4, fill:true, borderWidth:3}
337
- ]},
338
- options:{ responsive:true, maintainAspectRatio:false, plugins:{ legend:{position:'top'} }, scales:{ y:{beginAtZero:true, grid:{color:'#f1f5f9'}}, x:{grid:{display:false}}} }
339
- });
 
 
 
 
 
 
 
 
340
 
 
341
  const intCtx = document.getElementById('intentChart').getContext('2d');
342
- if(intChart) intChart.destroy();
343
- intChart = new Chart(intCtx,{
344
- type:'doughnut',
345
- data:{
346
- labels:['Mạng yếu','Huỷ gói','Đối thủ','Ít Data'],
347
- datasets:[{ data:[metrics.intents.network, metrics.intents.cancel, metrics.intents.competitor, metrics.intents.low_data], backgroundColor:['#0ea5e9','#ef4444','#eab308','#a855f7'], borderWidth:0 }]
348
- },
349
- options:{ responsive:true, maintainAspectRatio:false, cutout:'75%', plugins:{ legend:{display:false} } }
350
- });
 
 
 
 
 
 
351
 
 
352
  const sentCtx = document.getElementById('sentimentChart').getContext('2d');
353
- if(sentChart) sentChart.destroy();
354
- sentChart = new Chart(sentCtx,{
355
- type:'pie',
356
- data:{
357
- labels:['Tích cực','Trung lập','Tiêu cực'],
358
- datasets:[{ data:[metrics.sentiments.pos, metrics.sentiments.neu, metrics.sentiments.neg], backgroundColor:['#10b981','#cbd5e1','#f43f5e'], borderWidth:0 }]
359
- },
360
- options:{ responsive:true, maintainAspectRatio:false, plugins:{ legend:{position:'bottom'} } }
361
- });
 
 
 
 
 
 
362
  }
363
 
364
  function updateFeed() {
 
258
  }
259
  }
260
 
261
+ // --- CÁC HÀM HELPER & CHART ---
262
  function formatAHT(seconds) {
263
  if (!seconds || isNaN(seconds)) return "00:00";
264
  const m = Math.floor(seconds / 60).toString().padStart(2, '0');
 
327
  const retentionData = [65,68,62,70,75,72,78];
328
  const upsellData = [10,12,8,15,14,13,16];
329
 
330
+ // --- 1. BIỂU ĐỒ KINH DOANH (Line Chart) ---
331
  const busCtx = document.getElementById('businessChart').getContext('2d');
332
+ if (busChart) {
333
+ // Nếu đã , chỉ cập nhật data
334
+ busChart.data.labels = labels;
335
+ busChart.data.datasets[0].data = retentionData.slice(0,labels.length);
336
+ busChart.data.datasets[1].data = upsellData.slice(0,labels.length);
337
+ busChart.update('none'); // 'none' mode: Cập nhật ngay lập tức, không chạy animation
338
+ } else {
339
+ // Nếu chưa thì tạo mới
340
+ busChart = new Chart(busCtx,{
341
+ type:'line',
342
+ data:{ labels, datasets:[
343
+ {label:'Retention (%)', data: retentionData.slice(0,labels.length), borderColor:'#10b981', backgroundColor:'rgba(16,185,129,0.1)', tension:0.4, fill:true, borderWidth:3},
344
+ {label:'Upsell (%)', data: upsellData.slice(0,labels.length), borderColor:'#0ea5e9', backgroundColor:'rgba(14,165,233,0.1)', tension:0.4, fill:true, borderWidth:3}
345
+ ]},
346
+ options:{ responsive:true, maintainAspectRatio:false, plugins:{ legend:{position:'top'} }, scales:{ y:{beginAtZero:true, grid:{color:'#f1f5f9'}}, x:{grid:{display:false}}} }
347
+ });
348
+ }
349
 
350
+ // --- 2. BIỂU ĐỒ INTENT (Doughnut Chart) ---
351
  const intCtx = document.getElementById('intentChart').getContext('2d');
352
+ if (intChart) {
353
+ // Cập nhật data
354
+ intChart.data.datasets[0].data = [metrics.intents.network, metrics.intents.cancel, metrics.intents.competitor, metrics.intents.low_data];
355
+ intChart.update('none');
356
+ } else {
357
+ // Tạo mới
358
+ intChart = new Chart(intCtx,{
359
+ type:'doughnut',
360
+ data:{
361
+ labels:['Mạng yếu','Huỷ gói','Đối thủ','Ít Data'],
362
+ datasets:[{ data:[metrics.intents.network, metrics.intents.cancel, metrics.intents.competitor, metrics.intents.low_data], backgroundColor:['#0ea5e9','#ef4444','#eab308','#a855f7'], borderWidth:0 }]
363
+ },
364
+ options:{ responsive:true, maintainAspectRatio:false, cutout:'75%', plugins:{ legend:{display:false} } }
365
+ });
366
+ }
367
 
368
+ // --- 3. BIỂU ĐỒ CẢM XÚC (Pie Chart) ---
369
  const sentCtx = document.getElementById('sentimentChart').getContext('2d');
370
+ if (sentChart) {
371
+ // Cập nhật data
372
+ sentChart.data.datasets[0].data = [metrics.sentiments.pos, metrics.sentiments.neu, metrics.sentiments.neg];
373
+ sentChart.update('none');
374
+ } else {
375
+ // Tạo mới
376
+ sentChart = new Chart(sentCtx,{
377
+ type:'pie',
378
+ data:{
379
+ labels:['Tích cực','Trung lập','Tiêu cực'],
380
+ datasets:[{ data:[metrics.sentiments.pos, metrics.sentiments.neu, metrics.sentiments.neg], backgroundColor:['#10b981','#cbd5e1','#f43f5e'], borderWidth:0 }]
381
+ },
382
+ options:{ responsive:true, maintainAspectRatio:false, plugins:{ legend:{position:'bottom'} } }
383
+ });
384
+ }
385
  }
386
 
387
  function updateFeed() {