-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
80 lines (74 loc) · 2.17 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<head>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.0.0-release/chart.min.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.0/chart.min.js"></script>
</head>
<body>
<div class="container" >
<canvas id="cnv" ></canvas>
</div>
<script>
// Get the canvas element and its context
let mychart = document.getElementById("cnv").getContext("2d");
let initialData = [
450000,
250000,
900000,
350000,
150000
];
const data = {
labels: ['Lahore', 'Pindi', 'Karachi', 'Multan', 'Melsi'],
datasets: [{
label: 'Population',
data: initialData,
backgroundColor:[
'rgba(255, 99, 132, 0.6)',
'rgba(54, 162, 235, 0.6)',
'rgba(75, 192, 192, 0.6)',
'rgba(15, 140, 132, 0.6)',
'rgba(54, 162, 108, 0.6)',
],
},
{
label: 'Population',
data: initialData,
backgroundColor:[
'rgba(255, 99, 132, 0.6)',
'rgba(54, 162, 235, 0.6)',
'rgba(75, 192, 192, 0.6)',
'rgba(15, 140, 132, 0.6)',
'rgba(54, 162, 108, 0.6)',
],
},
],
}
const options = {
responsive : true,
// scales: {
// y:{
// beginAtZero: true,
// }
// }
}
// Create the initial chart
let createdChart = new Chart(mychart, {
type: 'bar',
data,
options
});
// Function to update chart data with random values
function updateChartData() {
let newData = initialData.map(() => Math.floor(Math.random() * 1000000));
createdChart.data.datasets[0].data = newData;
let anotherData = initialData.map(()=> Math.floor(Math.random()*1000000))
createdChart.data.datasets[1].data = anotherData;
createdChart.update();
}
setInterval(updateChartData, 2000);
</script>
<style>
.container{
width: 50%;
}
</style>
</body>