Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ // Simple animation for charts
+ const charts = document.querySelectorAll('.chart');
+
+ charts.forEach(chart => {
+ if (chart.classList.contains('line-chart')) {
+ drawLineChart(chart);
+ } else if (chart.classList.contains('bar-chart')) {
+ drawBarChart(chart);
+ } else if (chart.classList.contains('pie-chart')) {
+ drawPieChart(chart);
+ } else if (chart.classList.contains('scatter-plot')) {
+ drawScatterPlot(chart);
+ }
+ });
+ });
+
+ function drawLineChart(element) {
+ const ctx = document.createElement('canvas');
+ ctx.width = element.offsetWidth;
+ ctx.height = element.offsetHeight;
+ element.appendChild(ctx);
+ const context = ctx.getContext('2d');
+
+ // Simple line chart animation
+ let x = 0;
+ const points = [];
+
+ function animate() {
+ x += 5;
+ points.push({x, y: Math.sin(x/20) * 50 + 100});
+
+ context.clearRect(0, 0, ctx.width, ctx.height);
+ context.beginPath();
+ context.moveTo(points[0].x, points[0].y);
+
+ points.forEach(point => {
+ context.lineTo(point.x, point.y);
+ });
+
+ context.strokeStyle = '#2a6bf2';
+ context.stroke();
+
+ if (x < ctx.width) {
+ requestAnimationFrame(animate);
+ }
+ }
+
+ animate();
+ }
+
+ function drawBarChart(element) {
+ const ctx = document.createElement('canvas');
+ ctx.width = element.offsetWidth;
+ ctx.height = element.offsetHeight;
+ element.appendChild(ctx);
+ const context = ctx.getContext('2d');
+
+ const bars = 5;
+ const barWidth = ctx.width / (bars * 2);
+
+ for (let i = 0; i < bars; i++) {
+ const height = Math.random() * 150;
+ context.fillStyle = '#60a5fa';
+ context.fillRect(i * barWidth * 2 + barWidth/2, ctx.height - height, barWidth, height);
+ }
+ }
+
+ function drawPieChart(element) {
+ const ctx = document.createElement('canvas');
+ ctx.width = element.offsetWidth;
+ ctx.height = element.offsetHeight;
+ element.appendChild(ctx);
+ const context = ctx.getContext('2d');
+
+ const center = { x: ctx.width/2, y: ctx.height/2 };
+ const radius = Math.min(center.x, center.y) * 0.8;
+
+ const colors = ['#2a6bf2', '#60a5fa', '#1d4ed8'];
+ let startAngle = 0;
+
+ colors.forEach(color => {
+ const slice = Math.random() * Math.PI * 2/3;
+ context.beginPath();
+ context.moveTo(center.x, center.y);
+ context.arc(center.x, center.y, radius, startAngle, startAngle + slice);
+ context.fillStyle = color;
+ context.fill();
+ startAngle += slice;
+ });
+ }
+
+ function drawScatterPlot(element) {
+ const ctx = document.createElement('canvas');
+ ctx.width = element.offsetWidth;
+ ctx.height = element.offsetHeight;
+ element.appendChild(ctx);
+ const context = ctx.getContext('2d');
+
+ for (let i = 0; i < 20; i++) {
+ const x = Math.random() * ctx.width;
+ const y = Math.random() * ctx.height;
+
+ context.beginPath();
+ context.arc(x, y, 4, 0, Math.PI * 2);
+ context.fillStyle = '#2a6bf2';
+ context.fill();
+ }
+ }