Update index.html
Browse files- index.html +523 -474
index.html
CHANGED
|
@@ -3,553 +3,602 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
-
<
|
| 7 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 43 |
-
|
| 44 |
-
color: var(--foreground);
|
| 45 |
-
background-color: var(--background);
|
| 46 |
-
padding: 2rem;
|
| 47 |
}
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
max-width: 1200px;
|
| 51 |
-
margin: 0 auto;
|
| 52 |
-
padding: 0 1rem;
|
| 53 |
}
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 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 |
-
|
| 102 |
-
|
| 103 |
-
|
| 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 |
-
|
| 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 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
text-align: center;
|
| 225 |
-
margin: 1rem 0;
|
| 226 |
}
|
| 227 |
</style>
|
| 228 |
</head>
|
| 229 |
<body>
|
| 230 |
-
<div class="container">
|
| 231 |
-
<
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
<
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
-
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
<
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
</div>
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
</button>
|
| 297 |
-
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
</button>
|
| 300 |
-
<button onclick="copyChartToClipboard()"
|
| 301 |
Copy to Clipboard
|
| 302 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
</div>
|
| 304 |
-
</
|
| 305 |
-
</
|
| 306 |
</div>
|
| 307 |
|
| 308 |
<script>
|
| 309 |
let chartInstance = null;
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
const
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 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 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
.split("|")
|
| 351 |
-
.map(
|
| 352 |
-
.filter(
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 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
|
| 393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
}
|
| 395 |
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
},
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 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 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
|
|
|
| 476 |
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
}
|
|
|
|
| 483 |
}
|
| 484 |
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
chartInstance.data.datasets[index].backgroundColor =
|
| 489 |
-
|
| 490 |
chartInstance.update();
|
| 491 |
}
|
| 492 |
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
}
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
offCtx.
|
| 512 |
-
offCtx.
|
| 513 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
const link = document.createElement("a");
|
| 515 |
-
link.download = `
|
| 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 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
}
|
| 549 |
}
|
| 550 |
|
| 551 |
-
//
|
| 552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 554 |
</body>
|
| 555 |
-
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Modern Advanced Chart Maker with All Features</title>
|
| 7 |
+
<!-- Bootstrap CSS -->
|
| 8 |
+
<link
|
| 9 |
+
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
|
| 10 |
+
rel="stylesheet"
|
| 11 |
+
/>
|
| 12 |
+
<!-- Chart.js -->
|
| 13 |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 14 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
body {
|
| 16 |
+
background-color: #f8f9fa;
|
| 17 |
+
font-family: "Roboto", sans-serif;
|
|
|
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
+
.card {
|
| 20 |
+
margin-bottom: 20px;
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
+
.color-picker-container {
|
| 23 |
+
display: inline-block;
|
| 24 |
+
margin: 5px;
|
| 25 |
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
+
.color-picker-container input {
|
| 28 |
+
margin-top: 5px;
|
| 29 |
+
width: 3rem;
|
| 30 |
+
height: 3rem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
border: none;
|
| 32 |
+
padding: 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
}
|
| 34 |
+
#myChart {
|
| 35 |
+
background-color: white;
|
| 36 |
+
border-radius: 8px;
|
| 37 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
</style>
|
| 40 |
</head>
|
| 41 |
<body>
|
| 42 |
+
<div class="container my-4">
|
| 43 |
+
<h2 class="text-center mb-4">Modern Advanced Chart Maker</h2>
|
| 44 |
+
|
| 45 |
+
<!-- Chart Type and Data Input Card -->
|
| 46 |
+
<div class="card shadow-sm mb-4">
|
| 47 |
+
<div class="card-body">
|
| 48 |
+
<div class="row g-3 align-items-center">
|
| 49 |
+
<div class="col-md-4">
|
| 50 |
+
<label for="chartType" class="form-label">Select Chart Type:</label>
|
| 51 |
+
<select id="chartType" class="form-select">
|
| 52 |
+
<option value="bar">Bar</option>
|
| 53 |
+
<option value="line">Line</option>
|
| 54 |
+
<option value="pie">Pie</option>
|
| 55 |
+
<option value="doughnut">Doughnut</option>
|
| 56 |
+
<option value="polarArea">Polar Area</option>
|
| 57 |
+
<option value="radar">Radar</option>
|
| 58 |
+
</select>
|
| 59 |
+
</div>
|
| 60 |
+
<div class="col-md-8">
|
| 61 |
+
<label for="tableDataInput" class="form-label">Enter Tabular Data:</label>
|
| 62 |
+
<textarea
|
| 63 |
+
id="tableDataInput"
|
| 64 |
+
rows="6"
|
| 65 |
+
class="form-control"
|
| 66 |
+
placeholder="Paste your tabular data here...">| Year | Profit (in lakhs) | Revenue (in crores) | Expenses (in lakhs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|-------|------------------|---------------------|---------------------|
|
| 68 |
| Year 1 | 80 | 10 | 50 |
|
| 69 |
| Year 2 | 90 | 15 | 60 |
|
| 70 |
| Year 3 | 85 | 13 | 55 |
|
| 71 |
| Year 4 | 95 | 18 | 70 |
|
| 72 |
| Year 5 | 100 | 20 | 80 |</textarea>
|
| 73 |
+
</div>
|
| 74 |
+
</div>
|
| 75 |
+
<div class="mt-3 text-center">
|
| 76 |
+
<button onclick="generateChart()" class="btn btn-primary">
|
| 77 |
+
Generate Chart
|
| 78 |
+
</button>
|
| 79 |
+
</div>
|
| 80 |
</div>
|
| 81 |
+
</div>
|
| 82 |
|
| 83 |
+
<!-- Parsed Data Table Card -->
|
| 84 |
+
<div class="card shadow-sm mb-4">
|
| 85 |
+
<div class="card-header">Parsed Table Data</div>
|
| 86 |
+
<div class="card-body" id="tableContainer">
|
| 87 |
+
<!-- Table will be generated here -->
|
| 88 |
+
</div>
|
| 89 |
+
</div>
|
| 90 |
|
| 91 |
+
<!-- Chart Display Card -->
|
| 92 |
+
<div class="card shadow-sm mb-4">
|
| 93 |
+
<div class="card-header">Chart</div>
|
| 94 |
+
<div class="card-body">
|
| 95 |
+
<canvas id="myChart" height="150"></canvas>
|
| 96 |
+
</div>
|
| 97 |
+
</div>
|
| 98 |
|
| 99 |
+
<!-- Row Color Customization Card -->
|
| 100 |
+
<div class="card shadow-sm mb-4">
|
| 101 |
+
<div class="card-header">Customize Row Colors</div>
|
| 102 |
+
<div class="card-body" id="rowColorPickers">
|
| 103 |
+
<!-- Row color pickers will be generated here -->
|
| 104 |
+
</div>
|
| 105 |
+
</div>
|
| 106 |
|
| 107 |
+
<!-- Column Color Customization Card -->
|
| 108 |
+
<div class="card shadow-sm mb-4">
|
| 109 |
+
<div class="card-header">Customize Column Colors</div>
|
| 110 |
+
<div class="card-body" id="colColorPickers">
|
| 111 |
+
<!-- Column color pickers will be generated here -->
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
|
| 115 |
+
<!-- Advanced Chart Options Card -->
|
| 116 |
+
<div class="card shadow-sm mb-4">
|
| 117 |
+
<div class="card-header">Advanced Chart Options</div>
|
| 118 |
+
<div class="card-body">
|
| 119 |
+
<div class="row g-3">
|
| 120 |
+
<div class="col-md-4">
|
| 121 |
+
<label for="chartTitle" class="form-label">Chart Title:</label>
|
| 122 |
+
<input type="text" id="chartTitle" class="form-control" placeholder="Enter chart title" />
|
| 123 |
+
</div>
|
| 124 |
+
<div class="col-md-4">
|
| 125 |
+
<label for="xAxisLabel" class="form-label">X Axis Label:</label>
|
| 126 |
+
<input type="text" id="xAxisLabel" class="form-control" placeholder="Enter X axis label" />
|
| 127 |
+
</div>
|
| 128 |
+
<div class="col-md-4">
|
| 129 |
+
<label for="yAxisLabel" class="form-label">Y Axis Label:</label>
|
| 130 |
+
<input type="text" id="yAxisLabel" class="form-control" placeholder="Enter Y axis label" />
|
| 131 |
+
</div>
|
| 132 |
</div>
|
| 133 |
+
<div class="row g-3 mt-2">
|
| 134 |
+
<div class="col-md-6 form-check">
|
| 135 |
+
<input class="form-check-input" type="checkbox" id="toggleLegend" checked>
|
| 136 |
+
<label class="form-check-label" for="toggleLegend">
|
| 137 |
+
Show Legend
|
| 138 |
+
</label>
|
| 139 |
+
</div>
|
| 140 |
+
<div class="col-md-6 form-check">
|
| 141 |
+
<input class="form-check-input" type="checkbox" id="toggleGrid" checked>
|
| 142 |
+
<label class="form-check-label" for="toggleGrid">
|
| 143 |
+
Show Gridlines
|
| 144 |
+
</label>
|
| 145 |
+
</div>
|
| 146 |
+
</div>
|
| 147 |
+
<div class="mt-3 text-center">
|
| 148 |
+
<button onclick="updateChartOptions()" class="btn btn-secondary">
|
| 149 |
+
Update Chart Options
|
| 150 |
</button>
|
| 151 |
+
</div>
|
| 152 |
+
</div>
|
| 153 |
+
</div>
|
| 154 |
+
|
| 155 |
+
<!-- Watermark Options Card -->
|
| 156 |
+
<div class="card shadow-sm mb-4">
|
| 157 |
+
<div class="card-header">Watermark Options</div>
|
| 158 |
+
<div class="card-body">
|
| 159 |
+
<div class="row g-3">
|
| 160 |
+
<div class="col-md-4">
|
| 161 |
+
<label for="watermarkText" class="form-label">Watermark Text:</label>
|
| 162 |
+
<input type="text" id="watermarkText" class="form-control" placeholder="Enter watermark text" value="examups.com" />
|
| 163 |
+
</div>
|
| 164 |
+
<div class="col-md-4">
|
| 165 |
+
<label for="watermarkOpacity" class="form-label">Watermark Opacity (0 to 1):</label>
|
| 166 |
+
<input type="number" step="0.1" min="0" max="1" id="watermarkOpacity" class="form-control" value="0.5" />
|
| 167 |
+
</div>
|
| 168 |
+
<div class="col-md-4">
|
| 169 |
+
<label for="watermarkFontSize" class="form-label">Watermark Font Size (px):</label>
|
| 170 |
+
<input type="number" id="watermarkFontSize" class="form-control" value="20" />
|
| 171 |
+
</div>
|
| 172 |
+
</div>
|
| 173 |
+
<div class="row g-3 mt-2">
|
| 174 |
+
<div class="col-md-4">
|
| 175 |
+
<label for="watermarkPosition" class="form-label">Watermark Position:</label>
|
| 176 |
+
<select id="watermarkPosition" class="form-select">
|
| 177 |
+
<option value="center" selected>Center</option>
|
| 178 |
+
<option value="top-left">Top Left</option>
|
| 179 |
+
<option value="top-right">Top Right</option>
|
| 180 |
+
<option value="bottom-left">Bottom Left</option>
|
| 181 |
+
<option value="bottom-right">Bottom Right</option>
|
| 182 |
+
</select>
|
| 183 |
+
</div>
|
| 184 |
+
<div class="col-md-8">
|
| 185 |
+
<label for="watermarkImage" class="form-label">Upload Watermark Image (Optional):</label>
|
| 186 |
+
<input type="file" id="watermarkImage" class="form-control" accept="image/*" />
|
| 187 |
+
</div>
|
| 188 |
+
</div>
|
| 189 |
+
</div>
|
| 190 |
+
</div>
|
| 191 |
+
|
| 192 |
+
<!-- Export Options Card -->
|
| 193 |
+
<div class="card shadow-sm mb-4">
|
| 194 |
+
<div class="card-header">Export Options</div>
|
| 195 |
+
<div class="card-body">
|
| 196 |
+
<!-- New: Chart File Name Option -->
|
| 197 |
+
<div class="row g-3 mb-3">
|
| 198 |
+
<div class="col-md-12">
|
| 199 |
+
<label for="chartFileName" class="form-label">Chart File Name:</label>
|
| 200 |
+
<input type="text" id="chartFileName" class="form-control" value="chart" />
|
| 201 |
+
</div>
|
| 202 |
+
</div>
|
| 203 |
+
<div class="text-center">
|
| 204 |
+
<button onclick="downloadChart('png')" class="btn btn-success me-2">
|
| 205 |
+
Download as PNG
|
| 206 |
+
</button>
|
| 207 |
+
<button onclick="downloadChart('jpeg')" class="btn btn-success me-2">
|
| 208 |
+
Download as JPEG
|
| 209 |
</button>
|
| 210 |
+
<button onclick="copyChartToClipboard()" class="btn btn-warning me-2">
|
| 211 |
Copy to Clipboard
|
| 212 |
</button>
|
| 213 |
+
<button onclick="exportDataAsCSV()" class="btn btn-info me-2">
|
| 214 |
+
Export Data as CSV
|
| 215 |
+
</button>
|
| 216 |
+
<button onclick="exportChartConfigAsJSON()" class="btn btn-info">
|
| 217 |
+
Export Config as JSON
|
| 218 |
+
</button>
|
| 219 |
</div>
|
| 220 |
+
</div>
|
| 221 |
+
</div>
|
| 222 |
</div>
|
| 223 |
|
| 224 |
<script>
|
| 225 |
let chartInstance = null;
|
| 226 |
+
let currentChartConfig = {};
|
| 227 |
+
let rowColors = []; // One color per row (label)
|
| 228 |
+
let colColors = []; // One color per column (dataset)
|
| 229 |
+
|
| 230 |
+
// Blend two hex colors (50/50 average).
|
| 231 |
+
function blendColors(c1, c2) {
|
| 232 |
+
const r1 = parseInt(c1.slice(1, 3), 16);
|
| 233 |
+
const g1 = parseInt(c1.slice(3, 5), 16);
|
| 234 |
+
const b1 = parseInt(c1.slice(5, 7), 16);
|
| 235 |
+
const r2 = parseInt(c2.slice(1, 3), 16);
|
| 236 |
+
const g2 = parseInt(c2.slice(3, 5), 16);
|
| 237 |
+
const b2 = parseInt(c2.slice(5, 7), 16);
|
| 238 |
+
const r = Math.round((r1 + r2) / 2);
|
| 239 |
+
const g = Math.round((g1 + g2) / 2);
|
| 240 |
+
const b = Math.round((b1 + b2) / 2);
|
| 241 |
+
return "#" + [r, g, b].map(x => x.toString(16).padStart(2, "0")).join("");
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
// Parse tabular data (first column as labels).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
function parseTableData(input) {
|
| 246 |
+
const rows = input.trim().split("\n");
|
| 247 |
+
const headers = rows[0]
|
| 248 |
+
.split("|")
|
| 249 |
+
.map(h => h.trim())
|
| 250 |
+
.filter(h => h.length > 0);
|
| 251 |
+
const labels = [];
|
| 252 |
+
const datasets = headers.slice(1).map(header => ({
|
| 253 |
+
label: header,
|
| 254 |
+
data: [],
|
| 255 |
+
borderColor: "#333",
|
| 256 |
+
borderWidth: 1,
|
| 257 |
+
}));
|
| 258 |
+
for (let i = 2; i < rows.length; i++) {
|
| 259 |
+
const cells = rows[i]
|
| 260 |
.split("|")
|
| 261 |
+
.map(cell => cell.trim())
|
| 262 |
+
.filter(cell => cell.length > 0);
|
| 263 |
+
if (cells.length === headers.length) {
|
| 264 |
+
labels.push(cells[0]);
|
| 265 |
+
for (let j = 1; j < cells.length; j++) {
|
| 266 |
+
datasets[j - 1].data.push(parseFloat(cells[j]));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
}
|
| 268 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
}
|
| 270 |
+
return { headers, labels, datasets };
|
| 271 |
}
|
| 272 |
|
| 273 |
+
// Return a random hex color.
|
| 274 |
function getRandomColor() {
|
| 275 |
+
const letters = "0123456789ABCDEF";
|
| 276 |
+
let color = "#";
|
| 277 |
+
for (let i = 0; i < 6; i++) {
|
| 278 |
+
color += letters[Math.floor(Math.random() * 16)];
|
| 279 |
+
}
|
| 280 |
+
return color;
|
| 281 |
}
|
| 282 |
|
| 283 |
+
// Update composite colors by blending row and column colors.
|
| 284 |
+
function updateCompositeColors(datasets, labels) {
|
| 285 |
+
datasets.forEach((dataset, dIndex) => {
|
| 286 |
+
const composite = [];
|
| 287 |
+
for (let r = 0; r < labels.length; r++) {
|
| 288 |
+
composite.push(blendColors(rowColors[r], colColors[dIndex]));
|
| 289 |
+
}
|
| 290 |
+
dataset.backgroundColor = composite;
|
| 291 |
});
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
// Generate HTML table for parsed data.
|
| 295 |
+
function generateTable(headers, labels, datasets) {
|
| 296 |
+
let tableHTML = `<div class="table-responsive"><table class="table table-bordered">
|
| 297 |
+
<thead class="table-light"><tr>`;
|
| 298 |
+
headers.forEach(header => { tableHTML += `<th>${header}</th>`; });
|
| 299 |
tableHTML += `</tr></thead><tbody>`;
|
|
|
|
| 300 |
for (let i = 0; i < labels.length; i++) {
|
| 301 |
tableHTML += `<tr><td>${labels[i]}</td>`;
|
| 302 |
+
datasets.forEach(dataset => { tableHTML += `<td>${dataset.data[i]}</td>`; });
|
|
|
|
|
|
|
| 303 |
tableHTML += `</tr>`;
|
| 304 |
}
|
| 305 |
+
tableHTML += `</tbody></table></div>`;
|
| 306 |
document.getElementById("tableContainer").innerHTML = tableHTML;
|
| 307 |
}
|
| 308 |
|
| 309 |
+
// Generate the chart using Chart.js.
|
| 310 |
+
function generateChart() {
|
| 311 |
+
const chartType = document.getElementById("chartType").value;
|
| 312 |
+
const tableDataInput = document.getElementById("tableDataInput").value;
|
| 313 |
+
const { headers, labels, datasets } = parseTableData(tableDataInput);
|
| 314 |
+
|
| 315 |
+
// Initialize row and column colors.
|
| 316 |
+
rowColors = labels.map(() => getRandomColor());
|
| 317 |
+
colColors = datasets.map(() => getRandomColor());
|
| 318 |
+
|
| 319 |
+
// Set composite background colors.
|
| 320 |
+
updateCompositeColors(datasets, labels);
|
| 321 |
+
|
| 322 |
+
if (chartInstance) { chartInstance.destroy(); }
|
| 323 |
+
generateTable(headers, labels, datasets);
|
| 324 |
+
|
| 325 |
+
const ctx = document.getElementById("myChart").getContext("2d");
|
| 326 |
+
chartInstance = new Chart(ctx, {
|
| 327 |
+
type: chartType,
|
| 328 |
+
data: { labels: labels, datasets: datasets },
|
| 329 |
+
options: {
|
| 330 |
+
responsive: true,
|
| 331 |
+
plugins: {
|
| 332 |
+
legend: { display: true, position: "top" },
|
| 333 |
+
title: { display: true, text: `${headers[0]} vs Multiple Columns` },
|
| 334 |
},
|
| 335 |
+
scales: {
|
| 336 |
+
x: { grid: { display: true }, title: { display: false } },
|
| 337 |
+
y: { grid: { display: true }, title: { display: false } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
}
|
| 339 |
+
},
|
| 340 |
+
});
|
| 341 |
+
currentChartConfig = {
|
| 342 |
+
type: chartType,
|
| 343 |
+
data: { labels, datasets },
|
| 344 |
+
options: chartInstance.options,
|
| 345 |
+
};
|
| 346 |
+
generateRowColorPickers(labels);
|
| 347 |
+
generateColColorPickers(datasets);
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
// Generate row color pickers.
|
| 351 |
+
function generateRowColorPickers(labels) {
|
| 352 |
+
const container = document.getElementById("rowColorPickers");
|
| 353 |
+
container.innerHTML = "";
|
| 354 |
+
labels.forEach((label, index) => {
|
| 355 |
+
const pickerContainer = document.createElement("div");
|
| 356 |
+
pickerContainer.className = "color-picker-container";
|
| 357 |
+
pickerContainer.innerHTML = `
|
| 358 |
+
<label for="rowColor${index}">${label}</label>
|
| 359 |
+
<input type="color" id="rowColor${index}" class="form-control form-control-color" value="${rowColors[index]}" onchange="updateRowColor(${index}, this.value)">
|
| 360 |
+
`;
|
| 361 |
+
container.appendChild(pickerContainer);
|
| 362 |
+
});
|
| 363 |
+
}
|
| 364 |
|
| 365 |
+
// Generate column color pickers.
|
| 366 |
+
function generateColColorPickers(datasets) {
|
| 367 |
+
const container = document.getElementById("colColorPickers");
|
| 368 |
+
container.innerHTML = "";
|
| 369 |
+
datasets.forEach((dataset, index) => {
|
| 370 |
+
const pickerContainer = document.createElement("div");
|
| 371 |
+
pickerContainer.className = "color-picker-container";
|
| 372 |
+
pickerContainer.innerHTML = `
|
| 373 |
+
<label for="colColor${index}">${dataset.label}</label>
|
| 374 |
+
<input type="color" id="colColor${index}" class="form-control form-control-color" value="${colColors[index]}" onchange="updateColColor(${index}, this.value)">
|
| 375 |
+
`;
|
| 376 |
+
container.appendChild(pickerContainer);
|
| 377 |
+
});
|
| 378 |
+
}
|
| 379 |
|
| 380 |
+
// Update a row color and recalc composite colors.
|
| 381 |
+
function updateRowColor(index, color) {
|
| 382 |
+
rowColors[index] = color;
|
| 383 |
+
chartInstance.data.datasets.forEach((dataset, dIndex) => {
|
| 384 |
+
dataset.backgroundColor[index] = blendColors(rowColors[index], colColors[dIndex]);
|
| 385 |
+
});
|
| 386 |
+
chartInstance.update();
|
| 387 |
}
|
| 388 |
|
| 389 |
+
// Update a column color and recalc composite colors.
|
| 390 |
+
function updateColColor(index, color) {
|
| 391 |
+
colColors[index] = color;
|
| 392 |
+
chartInstance.data.datasets[index].backgroundColor =
|
| 393 |
+
chartInstance.data.labels.map((_, rIndex) => blendColors(rowColors[rIndex], colColors[index]));
|
| 394 |
chartInstance.update();
|
| 395 |
}
|
| 396 |
|
| 397 |
+
// Update advanced chart options.
|
| 398 |
+
function updateChartOptions() {
|
| 399 |
+
const newTitle = document.getElementById("chartTitle").value;
|
| 400 |
+
const newXAxisLabel = document.getElementById("xAxisLabel").value;
|
| 401 |
+
const newYAxisLabel = document.getElementById("yAxisLabel").value;
|
| 402 |
+
const showLegend = document.getElementById("toggleLegend").checked;
|
| 403 |
+
const showGrid = document.getElementById("toggleGrid").checked;
|
| 404 |
+
|
| 405 |
+
if(chartInstance.options.plugins.title){
|
| 406 |
+
chartInstance.options.plugins.title.text = newTitle || chartInstance.options.plugins.title.text;
|
| 407 |
+
}
|
| 408 |
+
if(chartInstance.options.scales.x){
|
| 409 |
+
chartInstance.options.scales.x.title = {
|
| 410 |
+
display: newXAxisLabel ? true : false,
|
| 411 |
+
text: newXAxisLabel,
|
| 412 |
+
};
|
| 413 |
+
chartInstance.options.scales.x.grid.display = showGrid;
|
| 414 |
+
}
|
| 415 |
+
if(chartInstance.options.scales.y){
|
| 416 |
+
chartInstance.options.scales.y.title = {
|
| 417 |
+
display: newYAxisLabel ? true : false,
|
| 418 |
+
text: newYAxisLabel,
|
| 419 |
+
};
|
| 420 |
+
chartInstance.options.scales.y.grid.display = showGrid;
|
| 421 |
+
}
|
| 422 |
+
chartInstance.options.plugins.legend.display = showLegend;
|
| 423 |
+
chartInstance.update();
|
| 424 |
+
currentChartConfig.options = chartInstance.options;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
// Helper: compute watermark coordinates based on position.
|
| 428 |
+
function getWatermarkCoordinates(width, height, position, wmWidth) {
|
| 429 |
+
let x, y;
|
| 430 |
+
switch(position) {
|
| 431 |
+
case "top-left":
|
| 432 |
+
x = 10 + wmWidth / 2; y = 10;
|
| 433 |
+
break;
|
| 434 |
+
case "top-right":
|
| 435 |
+
x = width - 10 - wmWidth / 2; y = 10;
|
| 436 |
+
break;
|
| 437 |
+
case "bottom-left":
|
| 438 |
+
x = 10 + wmWidth / 2; y = height - 10;
|
| 439 |
+
break;
|
| 440 |
+
case "bottom-right":
|
| 441 |
+
x = width - 10 - wmWidth / 2; y = height - 10;
|
| 442 |
+
break;
|
| 443 |
+
default: // center
|
| 444 |
+
x = width / 2; y = height / 2;
|
| 445 |
+
break;
|
| 446 |
+
}
|
| 447 |
+
return { x, y };
|
| 448 |
+
}
|
| 449 |
|
| 450 |
+
// Download chart with watermark (image or text), using custom file name.
|
| 451 |
+
function downloadChart(format) {
|
| 452 |
+
const originalCanvas = document.getElementById("myChart");
|
| 453 |
+
const offscreenCanvas = document.createElement("canvas");
|
| 454 |
+
offscreenCanvas.width = originalCanvas.width;
|
| 455 |
+
offscreenCanvas.height = originalCanvas.height;
|
| 456 |
+
const offCtx = offscreenCanvas.getContext("2d");
|
| 457 |
+
|
| 458 |
+
if (format === "jpeg") {
|
| 459 |
+
offCtx.fillStyle = "white";
|
| 460 |
+
offCtx.fillRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
|
| 461 |
+
}
|
| 462 |
+
offCtx.drawImage(originalCanvas, 0, 0);
|
| 463 |
+
|
| 464 |
+
const watermarkImageInput = document.getElementById("watermarkImage");
|
| 465 |
+
const watermarkOpacity = document.getElementById("watermarkOpacity").value;
|
| 466 |
+
|
| 467 |
+
if (watermarkImageInput.files && watermarkImageInput.files[0]) {
|
| 468 |
+
const reader = new FileReader();
|
| 469 |
+
reader.onload = function(e) {
|
| 470 |
+
const watermarkImg = new Image();
|
| 471 |
+
watermarkImg.onload = function() {
|
| 472 |
+
offCtx.globalAlpha = parseFloat(watermarkOpacity);
|
| 473 |
+
const coords = getWatermarkCoordinates(offscreenCanvas.width, offscreenCanvas.height, document.getElementById("watermarkPosition").value, watermarkImg.width);
|
| 474 |
+
offCtx.drawImage(watermarkImg, coords.x - watermarkImg.width / 2, coords.y - watermarkImg.height / 2);
|
| 475 |
+
offCtx.globalAlpha = 1.0;
|
| 476 |
+
let fileName = document.getElementById("chartFileName").value || "chart";
|
| 477 |
+
const link = document.createElement("a");
|
| 478 |
+
link.download = `${fileName}.${format}`;
|
| 479 |
+
link.href = offscreenCanvas.toDataURL(`image/${format}`);
|
| 480 |
+
link.click();
|
| 481 |
+
}
|
| 482 |
+
watermarkImg.src = e.target.result;
|
| 483 |
}
|
| 484 |
+
reader.readAsDataURL(watermarkImageInput.files[0]);
|
| 485 |
+
} else {
|
| 486 |
+
const watermarkText = document.getElementById("watermarkText").value;
|
| 487 |
+
const watermarkFontSize = document.getElementById("watermarkFontSize").value;
|
| 488 |
+
const watermarkPosition = document.getElementById("watermarkPosition").value;
|
| 489 |
+
|
| 490 |
+
offCtx.font = `${watermarkFontSize}px Arial`;
|
| 491 |
+
offCtx.fillStyle = `rgba(255,165,0,${watermarkOpacity})`;
|
| 492 |
+
|
| 493 |
+
let textAlign = "center", textBaseline = "middle";
|
| 494 |
+
if(watermarkPosition.includes("left")) { textAlign = "left"; }
|
| 495 |
+
else if(watermarkPosition.includes("right")) { textAlign = "right"; }
|
| 496 |
+
if(watermarkPosition.includes("top")) { textBaseline = "top"; }
|
| 497 |
+
else if(watermarkPosition.includes("bottom")) { textBaseline = "bottom"; }
|
| 498 |
+
offCtx.textAlign = textAlign;
|
| 499 |
+
offCtx.textBaseline = textBaseline;
|
| 500 |
+
|
| 501 |
+
const coords = getWatermarkCoordinates(offscreenCanvas.width, offscreenCanvas.height, watermarkPosition, parseInt(watermarkFontSize));
|
| 502 |
+
offCtx.fillText(watermarkText, coords.x, coords.y);
|
| 503 |
+
|
| 504 |
+
let fileName = document.getElementById("chartFileName").value || "chart";
|
| 505 |
const link = document.createElement("a");
|
| 506 |
+
link.download = `${fileName}.${format}`;
|
| 507 |
link.href = offscreenCanvas.toDataURL(`image/${format}`);
|
| 508 |
link.click();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 509 |
}
|
| 510 |
}
|
| 511 |
|
| 512 |
+
// Copy chart to clipboard with watermark (PNG), using custom file name if needed.
|
| 513 |
async function copyChartToClipboard() {
|
| 514 |
+
const originalCanvas = document.getElementById("myChart");
|
| 515 |
+
const offscreenCanvas = document.createElement("canvas");
|
| 516 |
+
offscreenCanvas.width = originalCanvas.width;
|
| 517 |
+
offscreenCanvas.height = originalCanvas.height;
|
| 518 |
+
const offCtx = offscreenCanvas.getContext("2d");
|
| 519 |
+
offCtx.drawImage(originalCanvas, 0, 0);
|
| 520 |
+
|
| 521 |
+
const watermarkImageInput = document.getElementById("watermarkImage");
|
| 522 |
+
const watermarkOpacity = document.getElementById("watermarkOpacity").value;
|
| 523 |
+
|
| 524 |
+
if (watermarkImageInput.files && watermarkImageInput.files[0]) {
|
| 525 |
+
const reader = new FileReader();
|
| 526 |
+
reader.onload = function(e) {
|
| 527 |
+
const watermarkImg = new Image();
|
| 528 |
+
watermarkImg.onload = function() {
|
| 529 |
+
offCtx.globalAlpha = parseFloat(watermarkOpacity);
|
| 530 |
+
const coords = getWatermarkCoordinates(offscreenCanvas.width, offscreenCanvas.height, document.getElementById("watermarkPosition").value, watermarkImg.width);
|
| 531 |
+
offCtx.drawImage(watermarkImg, coords.x - watermarkImg.width / 2, coords.y - watermarkImg.height / 2);
|
| 532 |
+
offCtx.globalAlpha = 1.0;
|
| 533 |
+
offscreenCanvas.toBlob(blob => {
|
| 534 |
+
const item = new ClipboardItem({ "image/png": blob });
|
| 535 |
+
navigator.clipboard.write([item])
|
| 536 |
+
.then(() => alert("Chart copied to clipboard with watermark!"))
|
| 537 |
+
.catch(err => alert("Error copying to clipboard: " + err));
|
| 538 |
+
}, "image/png");
|
| 539 |
+
}
|
| 540 |
+
watermarkImg.src = e.target.result;
|
| 541 |
+
}
|
| 542 |
+
reader.readAsDataURL(watermarkImageInput.files[0]);
|
| 543 |
+
} else {
|
| 544 |
+
const watermarkText = document.getElementById("watermarkText").value;
|
| 545 |
+
const watermarkFontSize = document.getElementById("watermarkFontSize").value;
|
| 546 |
+
const watermarkPosition = document.getElementById("watermarkPosition").value;
|
| 547 |
+
offCtx.font = `${watermarkFontSize}px Arial`;
|
| 548 |
+
offCtx.fillStyle = `rgba(255,165,0,${watermarkOpacity})`;
|
| 549 |
+
|
| 550 |
+
let textAlign = "center", textBaseline = "middle";
|
| 551 |
+
if(watermarkPosition.includes("left")) { textAlign = "left"; }
|
| 552 |
+
else if(watermarkPosition.includes("right")) { textAlign = "right"; }
|
| 553 |
+
if(watermarkPosition.includes("top")) { textBaseline = "top"; }
|
| 554 |
+
else if(watermarkPosition.includes("bottom")) { textBaseline = "bottom"; }
|
| 555 |
+
offCtx.textAlign = textAlign;
|
| 556 |
+
offCtx.textBaseline = textBaseline;
|
| 557 |
+
|
| 558 |
+
const coords = getWatermarkCoordinates(offscreenCanvas.width, offscreenCanvas.height, watermarkPosition, parseInt(watermarkFontSize));
|
| 559 |
+
offCtx.fillText(watermarkText, coords.x, coords.y);
|
| 560 |
+
|
| 561 |
+
offscreenCanvas.toBlob(blob => {
|
| 562 |
+
const item = new ClipboardItem({ "image/png": blob });
|
| 563 |
+
navigator.clipboard.write([item])
|
| 564 |
+
.then(() => alert("Chart copied to clipboard with watermark!"))
|
| 565 |
+
.catch(err => alert("Error copying to clipboard: " + err));
|
| 566 |
+
}, "image/png");
|
| 567 |
}
|
| 568 |
}
|
| 569 |
|
| 570 |
+
// Export parsed data as CSV using custom file name.
|
| 571 |
+
function exportDataAsCSV() {
|
| 572 |
+
const tableDataInput = document.getElementById("tableDataInput").value;
|
| 573 |
+
const { headers, labels, datasets } = parseTableData(tableDataInput);
|
| 574 |
+
let csvContent = headers.join(",") + "\n";
|
| 575 |
+
for (let i = 0; i < labels.length; i++){
|
| 576 |
+
let row = [labels[i]];
|
| 577 |
+
datasets.forEach(dataset => { row.push(dataset.data[i]); });
|
| 578 |
+
csvContent += row.join(",") + "\n";
|
| 579 |
+
}
|
| 580 |
+
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
| 581 |
+
let fileName = document.getElementById("chartFileName").value || "chart";
|
| 582 |
+
const link = document.createElement("a");
|
| 583 |
+
link.href = URL.createObjectURL(blob);
|
| 584 |
+
link.download = `${fileName}.csv`;
|
| 585 |
+
link.click();
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
// Export current chart configuration as JSON using custom file name.
|
| 589 |
+
function exportChartConfigAsJSON() {
|
| 590 |
+
const jsonStr = JSON.stringify(currentChartConfig, null, 2);
|
| 591 |
+
const blob = new Blob([jsonStr], { type: 'application/json' });
|
| 592 |
+
let fileName = document.getElementById("chartFileName").value || "chart";
|
| 593 |
+
const link = document.createElement("a");
|
| 594 |
+
link.href = URL.createObjectURL(blob);
|
| 595 |
+
link.download = `${fileName}_config.json`;
|
| 596 |
+
link.click();
|
| 597 |
+
}
|
| 598 |
</script>
|
| 599 |
+
<!-- Bootstrap Bundle with Popper -->
|
| 600 |
+
<script
|
| 601 |
+
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
|
| 602 |
+
></script>
|
| 603 |
</body>
|
| 604 |
+
</html>
|