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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<meta name="description" content="Professional chart maker with customization options and export features" />
|
| 7 |
+
<title>Professional Chart Maker</title>
|
| 8 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 9 |
+
<style>
|
| 10 |
+
:root {
|
| 11 |
+
--primary: #4f46e5;
|
| 12 |
+
--primary-hover: #4338ca;
|
| 13 |
+
--secondary: #6b7280;
|
| 14 |
+
--accent: #f59e0b;
|
| 15 |
+
--background: #ffffff;
|
| 16 |
+
--foreground: #111827;
|
| 17 |
+
--muted: #f3f4f6;
|
| 18 |
+
--muted-foreground: #6b7280;
|
| 19 |
+
--border: #e5e7eb;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/* Dark mode colors */
|
| 23 |
+
@media (prefers-color-scheme: dark) {
|
| 24 |
+
:root {
|
| 25 |
+
--primary: #6366f1;
|
| 26 |
+
--primary-hover: #818cf8;
|
| 27 |
+
--background: #1f2937;
|
| 28 |
+
--foreground: #f9fafb;
|
| 29 |
+
--muted: #374151;
|
| 30 |
+
--muted-foreground: #9ca3af;
|
| 31 |
+
--border: #374151;
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
* {
|
| 36 |
+
margin: 0;
|
| 37 |
+
padding: 0;
|
| 38 |
+
box-sizing: border-box;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
body {
|
| 42 |
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
|
| 43 |
+
line-height: 1.5;
|
| 44 |
+
color: var(--foreground);
|
| 45 |
+
background-color: var(--background);
|
| 46 |
+
padding: 2rem;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.container {
|
| 50 |
+
max-width: 1200px;
|
| 51 |
+
margin: 0 auto;
|
| 52 |
+
padding: 0 1rem;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.header {
|
| 56 |
+
text-align: center;
|
| 57 |
+
margin-bottom: 2rem;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.header h1 {
|
| 61 |
+
font-size: 2rem;
|
| 62 |
+
font-weight: 700;
|
| 63 |
+
margin-bottom: 1rem;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
.controls {
|
| 67 |
+
display: flex;
|
| 68 |
+
flex-wrap: wrap;
|
| 69 |
+
gap: 1rem;
|
| 70 |
+
margin-bottom: 2rem;
|
| 71 |
+
justify-content: center;
|
| 72 |
+
align-items: center;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
select, button {
|
| 76 |
+
padding: 0.5rem 1rem;
|
| 77 |
+
border-radius: 0.375rem;
|
| 78 |
+
border: 1px solid var(--border);
|
| 79 |
+
background-color: var(--background);
|
| 80 |
+
color: var(--foreground);
|
| 81 |
+
font-size: 0.875rem;
|
| 82 |
+
line-height: 1.25rem;
|
| 83 |
+
cursor: pointer;
|
| 84 |
+
transition: all 0.2s;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
select:hover, button:hover {
|
| 88 |
+
border-color: var(--primary);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
button {
|
| 92 |
+
background-color: var(--primary);
|
| 93 |
+
color: white;
|
| 94 |
+
font-weight: 500;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
button:hover {
|
| 98 |
+
background-color: var(--primary-hover);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
button:disabled {
|
| 102 |
+
opacity: 0.5;
|
| 103 |
+
cursor: not-allowed;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.textarea-container {
|
| 107 |
+
margin-bottom: 2rem;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
textarea {
|
| 111 |
+
width: 100%;
|
| 112 |
+
min-height: 200px;
|
| 113 |
+
padding: 1rem;
|
| 114 |
+
border-radius: 0.375rem;
|
| 115 |
+
border: 1px solid var(--border);
|
| 116 |
+
background-color: var(--background);
|
| 117 |
+
color: var(--foreground);
|
| 118 |
+
font-family: inherit;
|
| 119 |
+
font-size: 0.875rem;
|
| 120 |
+
line-height: 1.5;
|
| 121 |
+
resize: vertical;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
textarea:focus {
|
| 125 |
+
outline: none;
|
| 126 |
+
border-color: var(--primary);
|
| 127 |
+
box-shadow: 0 0 0 2px var(--primary-hover);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.table-container {
|
| 131 |
+
margin-bottom: 2rem;
|
| 132 |
+
overflow-x: auto;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
table {
|
| 136 |
+
width: 100%;
|
| 137 |
+
border-collapse: collapse;
|
| 138 |
+
text-align: left;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
th, td {
|
| 142 |
+
padding: 0.75rem 1rem;
|
| 143 |
+
border-bottom: 1px solid var(--border);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
th {
|
| 147 |
+
background-color: var(--muted);
|
| 148 |
+
font-weight: 600;
|
| 149 |
+
color: var(--foreground);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
tr:hover {
|
| 153 |
+
background-color: var(--muted);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
.chart-container {
|
| 157 |
+
position: relative;
|
| 158 |
+
height: 400px;
|
| 159 |
+
margin-bottom: 2rem;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
.color-pickers {
|
| 163 |
+
display: flex;
|
| 164 |
+
flex-wrap: wrap;
|
| 165 |
+
gap: 1rem;
|
| 166 |
+
margin-bottom: 2rem;
|
| 167 |
+
justify-content: center;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.color-picker {
|
| 171 |
+
display: flex;
|
| 172 |
+
align-items: center;
|
| 173 |
+
gap: 0.5rem;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
input[type="color"] {
|
| 177 |
+
width: 40px;
|
| 178 |
+
height: 40px;
|
| 179 |
+
padding: 0;
|
| 180 |
+
border: none;
|
| 181 |
+
border-radius: 0.375rem;
|
| 182 |
+
cursor: pointer;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
.actions {
|
| 186 |
+
display: flex;
|
| 187 |
+
flex-wrap: wrap;
|
| 188 |
+
gap: 1rem;
|
| 189 |
+
justify-content: center;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
@media (max-width: 640px) {
|
| 193 |
+
body {
|
| 194 |
+
padding: 1rem;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
.controls {
|
| 198 |
+
flex-direction: column;
|
| 199 |
+
align-items: stretch;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
.color-pickers {
|
| 203 |
+
flex-direction: column;
|
| 204 |
+
align-items: stretch;
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/* Loading state */
|
| 209 |
+
.loading {
|
| 210 |
+
opacity: 0.5;
|
| 211 |
+
pointer-events: none;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
/* Error message */
|
| 215 |
+
.error {
|
| 216 |
+
color: #ef4444;
|
| 217 |
+
text-align: center;
|
| 218 |
+
margin: 1rem 0;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
/* Success message */
|
| 222 |
+
.success {
|
| 223 |
+
color: #10b981;
|
| 224 |
+
text-align: center;
|
| 225 |
+
margin: 1rem 0;
|
| 226 |
+
}
|
| 227 |
+
</style>
|
| 228 |
+
</head>
|
| 229 |
+
<body>
|
| 230 |
+
<div class="container">
|
| 231 |
+
<header class="header">
|
| 232 |
+
<h1>Professional Chart Maker</h1>
|
| 233 |
+
<p>Create beautiful charts from your data with easy customization and export options</p>
|
| 234 |
+
</header>
|
| 235 |
+
|
| 236 |
+
<main>
|
| 237 |
+
<div class="controls">
|
| 238 |
+
<label for="chartType">Chart Type:</label>
|
| 239 |
+
<select id="chartType" aria-label="Select chart type">
|
| 240 |
+
<option value="bar">Bar Chart</option>
|
| 241 |
+
<option value="line">Line Chart</option>
|
| 242 |
+
<option value="pie">Pie Chart</option>
|
| 243 |
+
<option value="doughnut">Doughnut Chart</option>
|
| 244 |
+
<option value="polarArea">Polar Area Chart</option>
|
| 245 |
+
<option value="radar">Radar Chart</option>
|
| 246 |
+
</select>
|
| 247 |
+
</div>
|
| 248 |
+
|
| 249 |
+
<div class="textarea-container">
|
| 250 |
+
<label for="tableDataInput">Enter Your Data (Table Format):</label>
|
| 251 |
+
<textarea
|
| 252 |
+
id="tableDataInput"
|
| 253 |
+
rows="10"
|
| 254 |
+
aria-label="Table data input"
|
| 255 |
+
placeholder="Paste your tabular data here in the format:
|
| 256 |
+
| Year | Profit | Revenue |
|
| 257 |
+
|-------|---------|---------|
|
| 258 |
+
| 2020 | 100 | 500 |
|
| 259 |
+
| 2021 | 150 | 600 |"
|
| 260 |
+
>| Year | Profit (in lakhs) | Revenue (in crores) | Expenses (in lakhs) |
|
| 261 |
+
|-------|------------------|---------------------|---------------------|
|
| 262 |
+
| Year 1 | 80 | 10 | 50 |
|
| 263 |
+
| Year 2 | 90 | 15 | 60 |
|
| 264 |
+
| Year 3 | 85 | 13 | 55 |
|
| 265 |
+
| Year 4 | 95 | 18 | 70 |
|
| 266 |
+
| Year 5 | 100 | 20 | 80 |</textarea>
|
| 267 |
+
</div>
|
| 268 |
+
|
| 269 |
+
<button onclick="generateChart()" id="generateBtn">Generate Chart</button>
|
| 270 |
+
|
| 271 |
+
<div id="error" class="error" role="alert" hidden></div>
|
| 272 |
+
<div id="success" class="success" role="status" hidden></div>
|
| 273 |
+
|
| 274 |
+
<section aria-label="Data table" class="table-container">
|
| 275 |
+
<h2>Parsed Data</h2>
|
| 276 |
+
<div id="tableContainer"></div>
|
| 277 |
+
</section>
|
| 278 |
+
|
| 279 |
+
<section aria-label="Chart visualization">
|
| 280 |
+
<h2>Chart</h2>
|
| 281 |
+
<div class="chart-container">
|
| 282 |
+
<canvas id="myChart"></canvas>
|
| 283 |
+
</div>
|
| 284 |
+
</section>
|
| 285 |
+
|
| 286 |
+
<section aria-label="Chart customization">
|
| 287 |
+
<h2>Customize Colors</h2>
|
| 288 |
+
<div id="colorPickers" class="color-pickers"></div>
|
| 289 |
+
</section>
|
| 290 |
+
|
| 291 |
+
<section aria-label="Export options">
|
| 292 |
+
<h2>Export Chart</h2>
|
| 293 |
+
<div class="actions">
|
| 294 |
+
<button onclick="downloadChart('png')" aria-label="Download as PNG">
|
| 295 |
+
Download PNG
|
| 296 |
+
</button>
|
| 297 |
+
<button onclick="downloadChart('jpeg')" aria-label="Download as JPEG">
|
| 298 |
+
Download JPEG
|
| 299 |
+
</button>
|
| 300 |
+
<button onclick="copyChartToClipboard()" aria-label="Copy to clipboard">
|
| 301 |
+
Copy to Clipboard
|
| 302 |
+
</button>
|
| 303 |
+
</div>
|
| 304 |
+
</section>
|
| 305 |
+
</main>
|
| 306 |
+
</div>
|
| 307 |
+
|
| 308 |
+
<script>
|
| 309 |
+
let chartInstance = null;
|
| 310 |
+
|
| 311 |
+
function showError(message) {
|
| 312 |
+
const errorEl = document.getElementById('error');
|
| 313 |
+
errorEl.textContent = message;
|
| 314 |
+
errorEl.hidden = false;
|
| 315 |
+
setTimeout(() => {
|
| 316 |
+
errorEl.hidden = true;
|
| 317 |
+
}, 5000);
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
function showSuccess(message) {
|
| 321 |
+
const successEl = document.getElementById('success');
|
| 322 |
+
successEl.textContent = message;
|
| 323 |
+
successEl.hidden = false;
|
| 324 |
+
setTimeout(() => {
|
| 325 |
+
successEl.hidden = true;
|
| 326 |
+
}, 3000);
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
function setLoading(isLoading) {
|
| 330 |
+
const generateBtn = document.getElementById('generateBtn');
|
| 331 |
+
if (isLoading) {
|
| 332 |
+
generateBtn.disabled = true;
|
| 333 |
+
generateBtn.textContent = 'Generating...';
|
| 334 |
+
document.body.classList.add('loading');
|
| 335 |
+
} else {
|
| 336 |
+
generateBtn.disabled = false;
|
| 337 |
+
generateBtn.textContent = 'Generate Chart';
|
| 338 |
+
document.body.classList.remove('loading');
|
| 339 |
+
}
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
function parseTableData(input) {
|
| 343 |
+
try {
|
| 344 |
+
const rows = input.trim().split("\n");
|
| 345 |
+
if (rows.length < 3) {
|
| 346 |
+
throw new Error('Not enough data rows');
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
const headers = rows[0]
|
| 350 |
+
.split("|")
|
| 351 |
+
.map(h => h.trim())
|
| 352 |
+
.filter(h => h.length > 0);
|
| 353 |
+
|
| 354 |
+
if (headers.length < 2) {
|
| 355 |
+
throw new Error('Table must have at least 2 columns');
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
const labels = [];
|
| 359 |
+
const datasets = headers.slice(1).map(header => ({
|
| 360 |
+
label: header,
|
| 361 |
+
data: [],
|
| 362 |
+
backgroundColor: getRandomColor(),
|
| 363 |
+
borderColor: getRandomColor(),
|
| 364 |
+
borderWidth: 2
|
| 365 |
+
}));
|
| 366 |
+
|
| 367 |
+
for (let i = 2; i < rows.length; i++) {
|
| 368 |
+
const cells = rows[i]
|
| 369 |
+
.split("|")
|
| 370 |
+
.map(cell => cell.trim())
|
| 371 |
+
.filter(cell => cell.length > 0);
|
| 372 |
+
|
| 373 |
+
if (cells.length === headers.length) {
|
| 374 |
+
labels.push(cells[0]);
|
| 375 |
+
for (let j = 1; j < cells.length; j++) {
|
| 376 |
+
const value = parseFloat(cells[j]);
|
| 377 |
+
if (isNaN(value)) {
|
| 378 |
+
throw new Error(`Invalid number in row ${i + 1}, column ${j + 1}`);
|
| 379 |
+
}
|
| 380 |
+
datasets[j - 1].data.push(value);
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
return { headers, labels, datasets };
|
| 386 |
+
} catch (error) {
|
| 387 |
+
throw new Error(`Failed to parse table data: ${error.message}`);
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
function getRandomColor() {
|
| 392 |
+
const hue = Math.floor(Math.random() * 360);
|
| 393 |
+
return `hsl(${hue}, 70%, 50%)`;
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
function generateTable(headers, labels, datasets) {
|
| 397 |
+
let tableHTML = `<table><thead><tr>`;
|
| 398 |
+
headers.forEach(header => {
|
| 399 |
+
tableHTML += `<th scope="col">${header}</th>`;
|
| 400 |
+
});
|
| 401 |
+
tableHTML += `</tr></thead><tbody>`;
|
| 402 |
+
|
| 403 |
+
for (let i = 0; i < labels.length; i++) {
|
| 404 |
+
tableHTML += `<tr><td>${labels[i]}</td>`;
|
| 405 |
+
datasets.forEach(dataset => {
|
| 406 |
+
tableHTML += `<td>${dataset.data[i].toLocaleString()}</td>`;
|
| 407 |
+
});
|
| 408 |
+
tableHTML += `</tr>`;
|
| 409 |
+
}
|
| 410 |
+
tableHTML += `</tbody></table>`;
|
| 411 |
+
document.getElementById("tableContainer").innerHTML = tableHTML;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
async function generateChart() {
|
| 415 |
+
setLoading(true);
|
| 416 |
+
try {
|
| 417 |
+
const chartType = document.getElementById("chartType").value;
|
| 418 |
+
const tableDataInput = document.getElementById("tableDataInput").value;
|
| 419 |
+
const { headers, labels, datasets } = parseTableData(tableDataInput);
|
| 420 |
+
|
| 421 |
+
if (chartInstance) {
|
| 422 |
+
chartInstance.destroy();
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
generateTable(headers, labels, datasets);
|
| 426 |
+
|
| 427 |
+
const ctx = document.getElementById("myChart").getContext("2d");
|
| 428 |
+
chartInstance = new Chart(ctx, {
|
| 429 |
+
type: chartType,
|
| 430 |
+
data: {
|
| 431 |
+
labels: labels,
|
| 432 |
+
datasets: datasets
|
| 433 |
+
},
|
| 434 |
+
options: {
|
| 435 |
+
responsive: true,
|
| 436 |
+
maintainAspectRatio: false,
|
| 437 |
+
plugins: {
|
| 438 |
+
legend: {
|
| 439 |
+
position: "top",
|
| 440 |
+
labels: {
|
| 441 |
+
font: {
|
| 442 |
+
family: "'system-ui', sans-serif"
|
| 443 |
+
}
|
| 444 |
+
}
|
| 445 |
+
},
|
| 446 |
+
title: {
|
| 447 |
+
display: true,
|
| 448 |
+
text: `${headers[0]} vs ${headers.slice(1).join(", ")}`,
|
| 449 |
+
font: {
|
| 450 |
+
family: "'system-ui', sans-serif",
|
| 451 |
+
size: 16,
|
| 452 |
+
weight: 'bold'
|
| 453 |
+
}
|
| 454 |
+
}
|
| 455 |
+
},
|
| 456 |
+
animation: {
|
| 457 |
+
duration: 1000,
|
| 458 |
+
easing: 'easeInOutQuart'
|
| 459 |
+
}
|
| 460 |
+
}
|
| 461 |
+
});
|
| 462 |
+
|
| 463 |
+
const colorPickers = document.getElementById("colorPickers");
|
| 464 |
+
colorPickers.innerHTML = datasets.map((dataset, index) => `
|
| 465 |
+
<div class="color-picker">
|
| 466 |
+
<label for="color${index}">${dataset.label}:</label>
|
| 467 |
+
<input
|
| 468 |
+
type="color"
|
| 469 |
+
id="color${index}"
|
| 470 |
+
value="${dataset.backgroundColor}"
|
| 471 |
+
onchange="updateColor(${index}, this.value)"
|
| 472 |
+
aria-label="Choose color for ${dataset.label}"
|
| 473 |
+
>
|
| 474 |
+
</div>
|
| 475 |
+
`).join("");
|
| 476 |
+
|
| 477 |
+
showSuccess('Chart generated successfully!');
|
| 478 |
+
} catch (error) {
|
| 479 |
+
showError(error.message);
|
| 480 |
+
} finally {
|
| 481 |
+
setLoading(false);
|
| 482 |
+
}
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
function updateColor(index, color) {
|
| 486 |
+
if (!chartInstance) return;
|
| 487 |
+
|
| 488 |
+
chartInstance.data.datasets[index].backgroundColor = color;
|
| 489 |
+
chartInstance.data.datasets[index].borderColor = color;
|
| 490 |
+
chartInstance.update();
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
async function downloadChart(format) {
|
| 494 |
+
try {
|
| 495 |
+
const originalCanvas = document.getElementById("myChart");
|
| 496 |
+
const offscreenCanvas = document.createElement("canvas");
|
| 497 |
+
offscreenCanvas.width = originalCanvas.width;
|
| 498 |
+
offscreenCanvas.height = originalCanvas.height;
|
| 499 |
+
const offCtx = offscreenCanvas.getContext("2d");
|
| 500 |
+
|
| 501 |
+
if (format === "jpeg") {
|
| 502 |
+
offCtx.fillStyle = "white";
|
| 503 |
+
offCtx.fillRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
offCtx.drawImage(originalCanvas, 0, 0);
|
| 507 |
+
|
| 508 |
+
// Add watermark
|
| 509 |
+
offCtx.font = "16px system-ui";
|
| 510 |
+
offCtx.fillStyle = "rgba(0, 0, 0, 0.2)";
|
| 511 |
+
offCtx.textAlign = "right";
|
| 512 |
+
offCtx.fillText("Created by Examups.com", offscreenCanvas.width - 50, offscreenCanvas.height - 50);
|
| 513 |
+
|
| 514 |
+
const link = document.createElement("a");
|
| 515 |
+
link.download = `chart-${new Date().toISOString().slice(0, 10)}.${format}`;
|
| 516 |
+
link.href = offscreenCanvas.toDataURL(`image/${format}`);
|
| 517 |
+
link.click();
|
| 518 |
+
|
| 519 |
+
showSuccess(`Chart downloaded as ${format.toUpperCase()}`);
|
| 520 |
+
} catch (error) {
|
| 521 |
+
showError(`Failed to download chart: ${error.message}`);
|
| 522 |
+
}
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
async function copyChartToClipboard() {
|
| 526 |
+
try {
|
| 527 |
+
const originalCanvas = document.getElementById("myChart");
|
| 528 |
+
const offscreenCanvas = document.createElement("canvas");
|
| 529 |
+
offscreenCanvas.width = originalCanvas.width;
|
| 530 |
+
offscreenCanvas.height = originalCanvas.height;
|
| 531 |
+
const offCtx = offscreenCanvas.getContext("2d");
|
| 532 |
+
|
| 533 |
+
offCtx.drawImage(originalCanvas, 0, 0);
|
| 534 |
+
|
| 535 |
+
offCtx.font = "16px system-ui";
|
| 536 |
+
offCtx.fillStyle = "rgba(0, 0, 0, 0.5)";
|
| 537 |
+
offCtx.textAlign = "right";
|
| 538 |
+
offCtx.fillText("Created with Chart Maker", offscreenCanvas.width - 10, offscreenCanvas.height - 10);
|
| 539 |
+
|
| 540 |
+
const blob = await new Promise(resolve => offscreenCanvas.toBlob(resolve, 'image/png'));
|
| 541 |
+
await navigator.clipboard.write([
|
| 542 |
+
new ClipboardItem({ 'image/png': blob })
|
| 543 |
+
]);
|
| 544 |
+
|
| 545 |
+
showSuccess('Chart copied to clipboard!');
|
| 546 |
+
} catch (error) {
|
| 547 |
+
showError(`Failed to copy chart: ${error.message}`);
|
| 548 |
+
}
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
// Initialize the chart on page load
|
| 552 |
+
document.addEventListener('DOMContentLoaded', generateChart);
|
| 553 |
+
</script>
|
| 554 |
+
</body>
|
| 555 |
+
</html>
|