-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchart.html
146 lines (131 loc) · 4.61 KB
/
chart.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ApexCharts Line and Pie Chart</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/apexcharts/dist/apexcharts.css">
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.chart-container {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.chart {
width: 48%;
margin-bottom: 20px;
}
.buttons {
margin-bottom: 20px;
text-align: center;
}
.buttons button {
margin: 5px;
padding: 10px 15px;
cursor: pointer;
border: none;
background-color: #007bff;
color: white;
border-radius: 5px;
}
.buttons button.active {
background-color: #0056b3;
}
.pie-values {
margin-top: 20px;
text-align: center;
font-size: 16px;
display: flex;
justify-content: center;
gap: 30px;
}
.pie-values div {
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #f9f9f9;
}
</style>
</head>
<body>
<div class="buttons">
<button data-range="monthly">Monthly</button>
<button data-range="quarterly">Quarterly</button>
<button data-range="yearly">Yearly</button>
<button data-range="all" class="active">All</button>
</div>
<div class="chart-container">
<div id="line-chart" class="chart"></div>
<div id="pie-chart" class="chart"></div>
</div>
<div id="gsd-sales" class="sales-values"></div>
<div id="dms-sales" class="sales-values"></div>
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<script>
// Updated Data for Charts
const lineChartData = {
"monthly": [10, 15, 20, 25, 30],
"quarterly": [20, 40, 35, 50, 60],
"yearly": [30, 60, 75, 100, 120],
"all": [50, 75, 100, 125, 150]
};
const pieChartData = {
"monthly": [30, 70],
"quarterly": [40, 60],
"yearly": [60, 40],
"all": [50, 50]
};
const categories = ["Jan", "Feb", "Mar", "Apr", "May"];
// Line Chart Configuration
const lineChartOptions = {
chart: { type: 'line', height: 350 },
series: [{ name: 'Data', data: lineChartData["all"] }],
xaxis: { categories: categories },
title: { text: 'Line Chart' }
};
// Pie Chart Configuration
const pieChartOptions = {
chart: { type: 'pie', height: 350 },
series: pieChartData["all"],
labels: ['GSD', 'DMS'],
title: { text: 'Pie Chart' }
};
// Render Charts
const lineChart = new ApexCharts(document.querySelector("#line-chart"), lineChartOptions);
const pieChart = new ApexCharts(document.querySelector("#pie-chart"), pieChartOptions);
lineChart.render();
pieChart.render();
// Update Pie Chart Values Display
function updatePieValues(data) {
// Update GSD Sales
const gsdSalesElement = document.getElementById('gsd-sales');
gsdSalesElement.innerHTML = `<strong>GSD Sales:</strong> ${data[0]}`;
// Update DMS Sales
const dmsSalesElement = document.getElementById('dms-sales');
dmsSalesElement.innerHTML = `<strong>DMS Sales:</strong> ${data[1]}`;
}
// Initialize with "All" Data
updatePieValues(pieChartData["all"]);
// Button Click Event Listener
document.querySelectorAll('.buttons button').forEach(button => {
button.addEventListener('click', () => {
const range = button.getAttribute('data-range');
// Update Active Button
document.querySelectorAll('.buttons button').forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
// Update Line Chart
lineChart.updateSeries([{ data: lineChartData[range] || lineChartData["all"] }]);
// Update Pie Chart
const pieData = pieChartData[range] || pieChartData["all"];
pieChart.updateSeries(pieData);
// Update Pie Values Display
updatePieValues(pieData);
});
});
</script>
</body>
</html>