Update index.html
Browse files- index.html +627 -384
index.html
CHANGED
|
@@ -3,49 +3,98 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
-
<title>
|
| 7 |
<!-- Bootstrap CSS -->
|
| 8 |
-
<link
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
/>
|
| 12 |
<!-- Chart.js -->
|
| 13 |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
body {
|
| 16 |
-
background-color:
|
| 17 |
-
font-family:
|
|
|
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
-
.
|
|
|
|
| 20 |
margin-bottom: 20px;
|
| 21 |
}
|
| 22 |
-
.
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
-
.
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
}
|
| 34 |
.chart-container {
|
| 35 |
position: relative;
|
| 36 |
width: 100%;
|
| 37 |
-
height: 300px;
|
| 38 |
}
|
| 39 |
#myChart {
|
| 40 |
-
background-color:
|
|
|
|
| 41 |
border-radius: 8px;
|
| 42 |
-
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 43 |
}
|
| 44 |
.ad-container {
|
| 45 |
text-align: center;
|
| 46 |
margin: 20px 0;
|
| 47 |
}
|
| 48 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
@media (max-width: 576px) {
|
| 50 |
.color-picker-container {
|
| 51 |
display: block;
|
|
@@ -69,9 +118,7 @@
|
|
| 69 |
<body>
|
| 70 |
<!-- Top Google Ad -->
|
| 71 |
<div class="ad-container">
|
| 72 |
-
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2810665891608163"
|
| 73 |
-
crossorigin="anonymous"></script>
|
| 74 |
-
<!-- Examups Top -->
|
| 75 |
<ins class="adsbygoogle"
|
| 76 |
style="display:block"
|
| 77 |
data-ad-client="ca-pub-2810665891608163"
|
|
@@ -79,198 +126,243 @@
|
|
| 79 |
data-ad-format="auto"
|
| 80 |
data-full-width-responsive="true"></ins>
|
| 81 |
<script>
|
| 82 |
-
|
| 83 |
</script>
|
| 84 |
</div>
|
| 85 |
|
| 86 |
-
<
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
<div class="card shadow-sm mb-4">
|
| 91 |
<div class="card-body">
|
| 92 |
-
<
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
<div class="
|
| 105 |
-
|
| 106 |
-
<
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|-------|------------------|---------------------|---------------------|
|
| 109 |
| Year 1 | 80 | 10 | 50 |
|
| 110 |
| Year 2 | 90 | 15 | 60 |
|
| 111 |
| Year 3 | 85 | 13 | 55 |
|
| 112 |
| Year 4 | 95 | 18 | 70 |
|
| 113 |
-
| Year 5 | 100 | 20 | 80 |
|
| 114 |
-
</
|
|
|
|
|
|
|
|
|
|
| 115 |
</div>
|
| 116 |
</div>
|
| 117 |
-
<
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
<!-- Parsed Data Table Card -->
|
| 124 |
-
<div class="card shadow-sm mb-4">
|
| 125 |
-
<div class="card-header">Parsed Table Data</div>
|
| 126 |
-
<div class="card-body" id="tableContainer">
|
| 127 |
-
<!-- Table will be generated here -->
|
| 128 |
-
</div>
|
| 129 |
-
</div>
|
| 130 |
-
|
| 131 |
-
<!-- Chart Display Card -->
|
| 132 |
-
<div class="card shadow-sm mb-4">
|
| 133 |
-
<div class="card-header">Chart</div>
|
| 134 |
-
<div class="card-body">
|
| 135 |
-
<div class="chart-container">
|
| 136 |
-
<canvas id="myChart"></canvas>
|
| 137 |
-
</div>
|
| 138 |
-
</div>
|
| 139 |
-
</div>
|
| 140 |
-
|
| 141 |
-
<!-- Middle Google Ad (as a card) -->
|
| 142 |
-
<div class="card shadow-sm mb-4">
|
| 143 |
-
<div class="card-header">Sponsored</div>
|
| 144 |
-
<div class="card-body ad-container">
|
| 145 |
-
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2810665891608163"
|
| 146 |
-
crossorigin="anonymous"></script>
|
| 147 |
-
<!-- Examups Middle -->
|
| 148 |
-
<ins class="adsbygoogle"
|
| 149 |
-
style="display:block"
|
| 150 |
-
data-ad-client="ca-pub-2810665891608163"
|
| 151 |
-
data-ad-slot="8588732226"
|
| 152 |
-
data-ad-format="auto"
|
| 153 |
-
data-full-width-responsive="true"></ins>
|
| 154 |
-
<script>
|
| 155 |
-
(adsbygoogle = window.adsbygoogle || []).push({});
|
| 156 |
-
</script>
|
| 157 |
-
</div>
|
| 158 |
-
</div>
|
| 159 |
-
|
| 160 |
-
<!-- Row Color Customization Card -->
|
| 161 |
-
<div class="card shadow-sm mb-4">
|
| 162 |
-
<div class="card-header">Customize Row Colors</div>
|
| 163 |
-
<div class="card-body" id="rowColorPickers">
|
| 164 |
-
<!-- Row color pickers will be generated here -->
|
| 165 |
-
</div>
|
| 166 |
-
</div>
|
| 167 |
-
|
| 168 |
-
<!-- Column Color Customization Card -->
|
| 169 |
-
<div class="card shadow-sm mb-4">
|
| 170 |
-
<div class="card-header">Customize Column Colors</div>
|
| 171 |
-
<div class="card-body" id="colColorPickers">
|
| 172 |
-
<!-- Column color pickers will be generated here -->
|
| 173 |
-
</div>
|
| 174 |
-
</div>
|
| 175 |
-
|
| 176 |
-
<!-- Advanced Chart Options Card -->
|
| 177 |
-
<div class="card shadow-sm mb-4">
|
| 178 |
-
<div class="card-header">Advanced Chart Options</div>
|
| 179 |
-
<div class="card-body">
|
| 180 |
-
<div class="row g-3">
|
| 181 |
-
<div class="col-md-4">
|
| 182 |
-
<label for="chartTitle" class="form-label">Chart Title:</label>
|
| 183 |
-
<input type="text" id="chartTitle" class="form-control" placeholder="Enter chart title" />
|
| 184 |
-
</div>
|
| 185 |
-
<div class="col-md-4">
|
| 186 |
-
<label for="xAxisLabel" class="form-label">X Axis Label:</label>
|
| 187 |
-
<input type="text" id="xAxisLabel" class="form-control" placeholder="Enter X axis label" />
|
| 188 |
-
</div>
|
| 189 |
-
<div class="col-md-4">
|
| 190 |
-
<label for="yAxisLabel" class="form-label">Y Axis Label:</label>
|
| 191 |
-
<input type="text" id="yAxisLabel" class="form-control" placeholder="Enter Y axis label" />
|
| 192 |
</div>
|
| 193 |
</div>
|
| 194 |
-
<
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
<div class="col-md-6 form-check">
|
| 200 |
-
<input class="form-check-input" type="checkbox" id="toggleGrid" checked>
|
| 201 |
-
<label class="form-check-label" for="toggleGrid">Show Gridlines</label>
|
| 202 |
</div>
|
| 203 |
</div>
|
| 204 |
-
<
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
</div>
|
| 207 |
</div>
|
| 208 |
-
</div>
|
| 209 |
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
<div class="
|
| 216 |
-
<
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
<div class="col-md-4">
|
| 220 |
-
<label for="watermarkOpacity" class="form-label">Watermark Opacity (0 to 1):</label>
|
| 221 |
-
<input type="number" step="0.1" min="0" max="1" id="watermarkOpacity" class="form-control" value="0.5" />
|
| 222 |
-
</div>
|
| 223 |
-
<div class="col-md-4">
|
| 224 |
-
<label for="watermarkFontSize" class="form-label">Watermark Font Size (px):</label>
|
| 225 |
-
<input type="number" id="watermarkFontSize" class="form-control" value="20" />
|
| 226 |
</div>
|
| 227 |
</div>
|
| 228 |
-
<
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
</div>
|
| 243 |
</div>
|
| 244 |
</div>
|
| 245 |
-
</div>
|
| 246 |
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
</div>
|
| 257 |
</div>
|
| 258 |
-
<
|
| 259 |
-
|
| 260 |
-
<
|
| 261 |
-
<
|
| 262 |
-
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
</div>
|
| 265 |
</div>
|
| 266 |
</div>
|
| 267 |
</div>
|
| 268 |
|
| 269 |
-
<!--
|
|
|
|
|
|
|
| 270 |
<div class="ad-container">
|
| 271 |
-
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2810665891608163"
|
| 272 |
-
crossorigin="anonymous"></script>
|
| 273 |
-
<!-- Examups Footer -->
|
| 274 |
<ins class="adsbygoogle"
|
| 275 |
style="display:block"
|
| 276 |
data-ad-client="ca-pub-2810665891608163"
|
|
@@ -278,17 +370,42 @@
|
|
| 278 |
data-ad-format="auto"
|
| 279 |
data-full-width-responsive="true"></ins>
|
| 280 |
<script>
|
| 281 |
-
|
| 282 |
</script>
|
| 283 |
</div>
|
| 284 |
|
|
|
|
| 285 |
<script>
|
| 286 |
let chartInstance = null;
|
| 287 |
let currentChartConfig = {};
|
| 288 |
-
let rowColors = [];
|
| 289 |
-
let colColors = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
|
| 291 |
-
// Blend two hex colors (50/50 average).
|
| 292 |
function blendColors(c1, c2) {
|
| 293 |
const r1 = parseInt(c1.slice(1, 3), 16);
|
| 294 |
const g1 = parseInt(c1.slice(3, 5), 16);
|
|
@@ -302,19 +419,19 @@
|
|
| 302 |
return "#" + [r, g, b].map(x => x.toString(16).padStart(2, "0")).join("");
|
| 303 |
}
|
| 304 |
|
| 305 |
-
// Parse
|
| 306 |
function parseTableData(input) {
|
| 307 |
const rows = input.trim().split("\n");
|
| 308 |
-
const headers = rows[0].split("|").map(h => h.trim()).filter(h => h
|
| 309 |
const labels = [];
|
| 310 |
const datasets = headers.slice(1).map(header => ({
|
| 311 |
label: header,
|
| 312 |
data: [],
|
| 313 |
borderColor: "#333",
|
| 314 |
-
borderWidth: 1
|
| 315 |
}));
|
| 316 |
for (let i = 2; i < rows.length; i++) {
|
| 317 |
-
const cells = rows[i].split("|").map(cell => cell.trim()).filter(cell => cell
|
| 318 |
if (cells.length === headers.length) {
|
| 319 |
labels.push(cells[0]);
|
| 320 |
for (let j = 1; j < cells.length; j++) {
|
|
@@ -348,56 +465,102 @@
|
|
| 348 |
|
| 349 |
// Generate HTML table for parsed data.
|
| 350 |
function generateTable(headers, labels, datasets) {
|
| 351 |
-
let
|
| 352 |
-
headers.forEach(
|
| 353 |
-
|
| 354 |
for (let i = 0; i < labels.length; i++) {
|
| 355 |
-
|
| 356 |
-
datasets.forEach(
|
| 357 |
-
|
| 358 |
}
|
| 359 |
-
|
| 360 |
-
document.getElementById("tableContainer").innerHTML =
|
| 361 |
}
|
| 362 |
|
| 363 |
// Generate the chart using Chart.js.
|
| 364 |
function generateChart() {
|
| 365 |
const chartType = document.getElementById("chartType").value;
|
| 366 |
-
const
|
| 367 |
-
const { headers, labels, datasets } = parseTableData(
|
| 368 |
|
| 369 |
// Initialize row and column colors.
|
| 370 |
rowColors = labels.map(() => getRandomColor());
|
| 371 |
colColors = datasets.map(() => getRandomColor());
|
| 372 |
-
|
| 373 |
-
// Set composite background colors.
|
| 374 |
updateCompositeColors(datasets, labels);
|
| 375 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
if (chartInstance) { chartInstance.destroy(); }
|
| 377 |
generateTable(headers, labels, datasets);
|
| 378 |
-
|
| 379 |
const ctx = document.getElementById("myChart").getContext("2d");
|
| 380 |
chartInstance = new Chart(ctx, {
|
| 381 |
-
type:
|
| 382 |
-
data: { labels
|
| 383 |
options: {
|
| 384 |
responsive: true,
|
| 385 |
maintainAspectRatio: false,
|
|
|
|
| 386 |
plugins: {
|
| 387 |
-
legend: { display: true, position: "
|
| 388 |
-
title: {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
},
|
| 390 |
scales: {
|
| 391 |
-
x: { grid: { display: true }, title: { display: false } },
|
| 392 |
-
y: { grid: { display: true }, title: { display: false } }
|
| 393 |
}
|
| 394 |
-
}
|
| 395 |
});
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
|
|
|
| 401 |
generateRowColorPickers(labels);
|
| 402 |
generateColColorPickers(datasets);
|
| 403 |
}
|
|
@@ -407,13 +570,11 @@
|
|
| 407 |
const container = document.getElementById("rowColorPickers");
|
| 408 |
container.innerHTML = "";
|
| 409 |
labels.forEach((label, index) => {
|
| 410 |
-
const
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
<
|
| 414 |
-
|
| 415 |
-
`;
|
| 416 |
-
container.appendChild(pickerContainer);
|
| 417 |
});
|
| 418 |
}
|
| 419 |
|
|
@@ -421,27 +582,23 @@
|
|
| 421 |
function generateColColorPickers(datasets) {
|
| 422 |
const container = document.getElementById("colColorPickers");
|
| 423 |
container.innerHTML = "";
|
| 424 |
-
datasets.forEach((
|
| 425 |
-
const
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
<
|
| 429 |
-
|
| 430 |
-
`;
|
| 431 |
-
container.appendChild(pickerContainer);
|
| 432 |
});
|
| 433 |
}
|
| 434 |
|
| 435 |
-
// Update a row color and recalc composite colors.
|
| 436 |
function updateRowColor(index, color) {
|
| 437 |
rowColors[index] = color;
|
| 438 |
-
chartInstance.data.datasets.forEach((
|
| 439 |
-
|
| 440 |
});
|
| 441 |
chartInstance.update();
|
| 442 |
}
|
| 443 |
|
| 444 |
-
// Update a column color and recalc composite colors.
|
| 445 |
function updateColColor(index, color) {
|
| 446 |
colColors[index] = color;
|
| 447 |
chartInstance.data.datasets[index].backgroundColor =
|
|
@@ -449,70 +606,68 @@
|
|
| 449 |
chartInstance.update();
|
| 450 |
}
|
| 451 |
|
| 452 |
-
// Update advanced chart options.
|
| 453 |
function updateChartOptions() {
|
| 454 |
const newTitle = document.getElementById("chartTitle").value;
|
| 455 |
-
const
|
| 456 |
-
const
|
| 457 |
const showLegend = document.getElementById("toggleLegend").checked;
|
| 458 |
const showGrid = document.getElementById("toggleGrid").checked;
|
| 459 |
-
|
| 460 |
-
if(chartInstance.options.plugins.title){
|
| 461 |
chartInstance.options.plugins.title.text = newTitle || chartInstance.options.plugins.title.text;
|
| 462 |
}
|
| 463 |
-
if(chartInstance.options.scales.x){
|
| 464 |
-
chartInstance.options.scales.x.title = {
|
| 465 |
-
display: newXAxisLabel ? true : false,
|
| 466 |
-
text: newXAxisLabel,
|
| 467 |
-
};
|
| 468 |
chartInstance.options.scales.x.grid.display = showGrid;
|
| 469 |
}
|
| 470 |
-
if(chartInstance.options.scales.y){
|
| 471 |
-
chartInstance.options.scales.y.title = {
|
| 472 |
-
display: newYAxisLabel ? true : false,
|
| 473 |
-
text: newYAxisLabel,
|
| 474 |
-
};
|
| 475 |
chartInstance.options.scales.y.grid.display = showGrid;
|
| 476 |
}
|
| 477 |
chartInstance.options.plugins.legend.display = showLegend;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
chartInstance.update();
|
| 479 |
currentChartConfig.options = chartInstance.options;
|
| 480 |
}
|
| 481 |
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
x = width / 2; y = height / 2;
|
| 500 |
-
break;
|
| 501 |
}
|
| 502 |
-
|
|
|
|
| 503 |
}
|
| 504 |
|
| 505 |
-
//
|
| 506 |
function drawPieTooltips(ctx) {
|
| 507 |
if (chartInstance.config.type === "pie" || chartInstance.config.type === "doughnut") {
|
| 508 |
const meta = chartInstance.getDatasetMeta(0);
|
| 509 |
-
const
|
| 510 |
-
const total =
|
| 511 |
meta.data.forEach((arc, index) => {
|
| 512 |
const pos = arc.tooltipPosition();
|
| 513 |
-
const
|
| 514 |
-
|
| 515 |
-
ctx.fillStyle = "black";
|
| 516 |
ctx.font = "bold 12px Arial";
|
| 517 |
ctx.textAlign = "center";
|
| 518 |
ctx.textBaseline = "middle";
|
|
@@ -521,164 +676,252 @@
|
|
| 521 |
}
|
| 522 |
}
|
| 523 |
|
| 524 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
function downloadChart(format) {
|
| 526 |
-
const
|
| 527 |
-
const
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
|
|
|
| 532 |
if (format === "jpeg") {
|
| 533 |
offCtx.fillStyle = "white";
|
| 534 |
-
offCtx.fillRect(0, 0,
|
| 535 |
}
|
| 536 |
-
offCtx.drawImage(
|
| 537 |
-
|
| 538 |
-
// If chart is pie/doughnut, draw tooltip percentages on image.
|
| 539 |
if (chartInstance.config.type === "pie" || chartInstance.config.type === "doughnut") {
|
| 540 |
drawPieTooltips(offCtx);
|
| 541 |
}
|
| 542 |
-
|
| 543 |
-
const
|
| 544 |
-
const
|
| 545 |
-
|
| 546 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
const reader = new FileReader();
|
| 548 |
-
reader.onload = function(e) {
|
| 549 |
-
const
|
| 550 |
-
|
| 551 |
-
offCtx.globalAlpha = parseFloat(
|
| 552 |
-
|
| 553 |
-
offCtx.drawImage(watermarkImg, coords.x - watermarkImg.width / 2, coords.y - watermarkImg.height / 2);
|
| 554 |
offCtx.globalAlpha = 1.0;
|
| 555 |
-
let
|
| 556 |
const link = document.createElement("a");
|
| 557 |
-
link.download = `${
|
| 558 |
-
link.href =
|
| 559 |
link.click();
|
| 560 |
}
|
| 561 |
-
|
| 562 |
}
|
| 563 |
-
reader.readAsDataURL(
|
| 564 |
} else {
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
const watermarkPosition = document.getElementById("watermarkPosition").value;
|
| 568 |
-
|
| 569 |
-
offCtx.font = `${watermarkFontSize}px Arial`;
|
| 570 |
-
offCtx.fillStyle = `rgba(255,165,0,${watermarkOpacity})`;
|
| 571 |
-
|
| 572 |
-
let textAlign = "center", textBaseline = "middle";
|
| 573 |
-
if (watermarkPosition.includes("left")) { textAlign = "left"; }
|
| 574 |
-
else if (watermarkPosition.includes("right")) { textAlign = "right"; }
|
| 575 |
-
if (watermarkPosition.includes("top")) { textBaseline = "top"; }
|
| 576 |
-
else if (watermarkPosition.includes("bottom")) { textBaseline = "bottom"; }
|
| 577 |
-
offCtx.textAlign = textAlign;
|
| 578 |
-
offCtx.textBaseline = textBaseline;
|
| 579 |
-
|
| 580 |
-
const coords = getWatermarkCoordinates(offscreenCanvas.width, offscreenCanvas.height, watermarkPosition, parseInt(watermarkFontSize));
|
| 581 |
-
offCtx.fillText(watermarkText, coords.x, coords.y);
|
| 582 |
-
|
| 583 |
-
let fileName = document.getElementById("chartFileName").value || "chart";
|
| 584 |
const link = document.createElement("a");
|
| 585 |
-
link.download = `${
|
| 586 |
-
link.href =
|
| 587 |
link.click();
|
| 588 |
}
|
| 589 |
}
|
| 590 |
|
| 591 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
async function copyChartToClipboard() {
|
| 593 |
-
const
|
| 594 |
-
const
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
offCtx
|
| 599 |
-
|
| 600 |
-
|
| 601 |
if (chartInstance.config.type === "pie" || chartInstance.config.type === "doughnut") {
|
| 602 |
drawPieTooltips(offCtx);
|
| 603 |
}
|
| 604 |
-
|
| 605 |
-
const
|
| 606 |
-
const
|
| 607 |
-
|
| 608 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
const reader = new FileReader();
|
| 610 |
-
reader.onload = function(e) {
|
| 611 |
-
const
|
| 612 |
-
|
| 613 |
-
offCtx.globalAlpha = parseFloat(
|
| 614 |
-
|
| 615 |
-
offCtx.drawImage(watermarkImg, coords.x - watermarkImg.width / 2, coords.y - watermarkImg.height / 2);
|
| 616 |
offCtx.globalAlpha = 1.0;
|
| 617 |
-
|
| 618 |
const item = new ClipboardItem({ "image/png": blob });
|
| 619 |
navigator.clipboard.write([item])
|
| 620 |
-
.then(() => alert("Chart copied
|
| 621 |
-
.catch(err => alert("Error copying
|
| 622 |
}, "image/png");
|
| 623 |
}
|
| 624 |
-
|
| 625 |
}
|
| 626 |
-
reader.readAsDataURL(
|
| 627 |
} else {
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
const watermarkPosition = document.getElementById("watermarkPosition").value;
|
| 631 |
-
offCtx.font = `${watermarkFontSize}px Arial`;
|
| 632 |
-
offCtx.fillStyle = `rgba(255,165,0,${watermarkOpacity})`;
|
| 633 |
-
|
| 634 |
-
let textAlign = "center", textBaseline = "middle";
|
| 635 |
-
if (watermarkPosition.includes("left")) { textAlign = "left"; }
|
| 636 |
-
else if (watermarkPosition.includes("right")) { textAlign = "right"; }
|
| 637 |
-
if (watermarkPosition.includes("top")) { textBaseline = "top"; }
|
| 638 |
-
else if (watermarkPosition.includes("bottom")) { textBaseline = "bottom"; }
|
| 639 |
-
offCtx.textAlign = textAlign;
|
| 640 |
-
offCtx.textBaseline = textBaseline;
|
| 641 |
-
|
| 642 |
-
const coords = getWatermarkCoordinates(offscreenCanvas.width, offscreenCanvas.height, watermarkPosition, parseInt(watermarkFontSize));
|
| 643 |
-
offCtx.fillText(watermarkText, coords.x, coords.y);
|
| 644 |
-
|
| 645 |
-
offscreenCanvas.toBlob(blob => {
|
| 646 |
const item = new ClipboardItem({ "image/png": blob });
|
| 647 |
navigator.clipboard.write([item])
|
| 648 |
-
.then(() => alert("Chart copied
|
| 649 |
-
.catch(err => alert("Error copying
|
| 650 |
}, "image/png");
|
| 651 |
}
|
| 652 |
}
|
| 653 |
|
| 654 |
-
// Export parsed data as CSV
|
| 655 |
function exportDataAsCSV() {
|
| 656 |
-
const
|
| 657 |
-
const { headers, labels, datasets } = parseTableData(
|
| 658 |
-
let
|
| 659 |
-
for (let i = 0; i < labels.length; i++){
|
| 660 |
let row = [labels[i]];
|
| 661 |
-
datasets.forEach(
|
| 662 |
-
|
| 663 |
}
|
| 664 |
-
const blob = new Blob([
|
| 665 |
-
let
|
| 666 |
const link = document.createElement("a");
|
| 667 |
link.href = URL.createObjectURL(blob);
|
| 668 |
-
link.download = `${
|
| 669 |
link.click();
|
| 670 |
}
|
| 671 |
|
| 672 |
-
// Export
|
| 673 |
function exportChartConfigAsJSON() {
|
| 674 |
const jsonStr = JSON.stringify(currentChartConfig, null, 2);
|
| 675 |
const blob = new Blob([jsonStr], { type: 'application/json' });
|
| 676 |
-
let
|
| 677 |
const link = document.createElement("a");
|
| 678 |
link.href = URL.createObjectURL(blob);
|
| 679 |
-
link.download = `${
|
| 680 |
link.click();
|
| 681 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 682 |
</script>
|
| 683 |
<!-- Bootstrap Bundle with Popper -->
|
| 684 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Advanced Chart Maker - Modern UI</title>
|
| 7 |
<!-- Bootstrap CSS -->
|
| 8 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
|
| 9 |
+
<!-- Google Fonts -->
|
| 10 |
+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
|
|
|
|
| 11 |
<!-- Chart.js -->
|
| 12 |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 13 |
+
<!-- Chart.js Zoom Plugin -->
|
| 14 |
+
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom@1.2.1/dist/chartjs-plugin-zoom.min.js"></script>
|
| 15 |
+
<!-- canvas2svg for SVG Export -->
|
| 16 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/canvas2svg/1.0.18/canvas2svg.min.js"></script>
|
| 17 |
+
<!-- jsPDF for PDF Export -->
|
| 18 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
|
| 19 |
<style>
|
| 20 |
+
:root {
|
| 21 |
+
--primary-color: #007bff;
|
| 22 |
+
--secondary-color: #6c757d;
|
| 23 |
+
--light-color: #f8f9fa;
|
| 24 |
+
--dark-color: #343a40;
|
| 25 |
+
--card-bg: #ffffff;
|
| 26 |
+
--card-border: #e0e0e0;
|
| 27 |
+
--shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
body {
|
| 30 |
+
background-color: var(--light-color);
|
| 31 |
+
font-family: 'Roboto', sans-serif;
|
| 32 |
+
margin: 0;
|
| 33 |
+
padding: 0;
|
| 34 |
+
color: var(--dark-color);
|
| 35 |
}
|
| 36 |
+
.container {
|
| 37 |
+
margin-top: 20px;
|
| 38 |
margin-bottom: 20px;
|
| 39 |
}
|
| 40 |
+
.card {
|
| 41 |
+
background-color: var(--card-bg);
|
| 42 |
+
border: 1px solid var(--card-border);
|
| 43 |
+
box-shadow: var(--shadow);
|
| 44 |
+
border-radius: 8px;
|
| 45 |
+
transition: transform 0.2s ease;
|
| 46 |
}
|
| 47 |
+
.card:hover {
|
| 48 |
+
transform: translateY(-5px);
|
| 49 |
+
}
|
| 50 |
+
.card-header {
|
| 51 |
+
background-color: var(--primary-color);
|
| 52 |
+
color: #fff;
|
| 53 |
+
border-top-left-radius: 8px;
|
| 54 |
+
border-top-right-radius: 8px;
|
| 55 |
+
font-weight: 500;
|
| 56 |
+
}
|
| 57 |
+
.form-label {
|
| 58 |
+
font-weight: 500;
|
| 59 |
}
|
| 60 |
.chart-container {
|
| 61 |
position: relative;
|
| 62 |
width: 100%;
|
| 63 |
+
height: 300px;
|
| 64 |
}
|
| 65 |
#myChart {
|
| 66 |
+
background-color: #fff;
|
| 67 |
+
border: 2px solid #cccccc;
|
| 68 |
border-radius: 8px;
|
|
|
|
| 69 |
}
|
| 70 |
.ad-container {
|
| 71 |
text-align: center;
|
| 72 |
margin: 20px 0;
|
| 73 |
}
|
| 74 |
+
/* Modern button styles */
|
| 75 |
+
.btn {
|
| 76 |
+
border-radius: 50px;
|
| 77 |
+
padding: 0.5rem 1.5rem;
|
| 78 |
+
font-weight: 500;
|
| 79 |
+
text-transform: uppercase;
|
| 80 |
+
letter-spacing: 0.5px;
|
| 81 |
+
transition: background-color 0.3s ease, transform 0.2s ease;
|
| 82 |
+
}
|
| 83 |
+
.btn:hover {
|
| 84 |
+
transform: translateY(-2px);
|
| 85 |
+
}
|
| 86 |
+
/* Three-column desktop layout */
|
| 87 |
+
@media (min-width: 992px) {
|
| 88 |
+
.col-desktop {
|
| 89 |
+
margin-bottom: 20px;
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
/* Responsive adjustments */
|
| 93 |
+
@media (max-width: 992px) {
|
| 94 |
+
.col-desktop {
|
| 95 |
+
margin-bottom: 20px;
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
@media (max-width: 576px) {
|
| 99 |
.color-picker-container {
|
| 100 |
display: block;
|
|
|
|
| 118 |
<body>
|
| 119 |
<!-- Top Google Ad -->
|
| 120 |
<div class="ad-container">
|
| 121 |
+
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2810665891608163" crossorigin="anonymous"></script>
|
|
|
|
|
|
|
| 122 |
<ins class="adsbygoogle"
|
| 123 |
style="display:block"
|
| 124 |
data-ad-client="ca-pub-2810665891608163"
|
|
|
|
| 126 |
data-ad-format="auto"
|
| 127 |
data-full-width-responsive="true"></ins>
|
| 128 |
<script>
|
| 129 |
+
(adsbygoogle = window.adsbygoogle || []).push({});
|
| 130 |
</script>
|
| 131 |
</div>
|
| 132 |
|
| 133 |
+
<!-- Header: Chart File Name -->
|
| 134 |
+
<div class="container my-3">
|
| 135 |
+
<div class="card">
|
| 136 |
+
<div class="card-header">Chart File Name</div>
|
|
|
|
| 137 |
<div class="card-body">
|
| 138 |
+
<input type="text" id="chartFileName" class="form-control" value="chart" />
|
| 139 |
+
</div>
|
| 140 |
+
</div>
|
| 141 |
+
</div>
|
| 142 |
+
|
| 143 |
+
<!-- Main Content: Three Column Layout -->
|
| 144 |
+
<div class="container">
|
| 145 |
+
<div class="row">
|
| 146 |
+
<!-- Left Sidebar -->
|
| 147 |
+
<div class="col-lg-3 col-md-4 col-desktop">
|
| 148 |
+
<!-- Chart Data & Type Card -->
|
| 149 |
+
<div class="card mb-3">
|
| 150 |
+
<div class="card-header">Chart Data & Type</div>
|
| 151 |
+
<div class="card-body">
|
| 152 |
+
<div class="mb-3">
|
| 153 |
+
<label for="chartType" class="form-label">Select Chart Type:</label>
|
| 154 |
+
<select id="chartType" class="form-select">
|
| 155 |
+
<option value="bar">Bar Chart</option>
|
| 156 |
+
<option value="line">Line Chart</option>
|
| 157 |
+
<option value="pie">Pie Chart</option>
|
| 158 |
+
<option value="doughnut">Doughnut Chart</option>
|
| 159 |
+
<option value="area">Area Chart</option>
|
| 160 |
+
<option value="scatter">Scatter Plot</option>
|
| 161 |
+
<option value="bubble">Bubble Chart</option>
|
| 162 |
+
<option value="radar">Radar Chart</option>
|
| 163 |
+
<option value="polarArea">Polar Area Chart</option>
|
| 164 |
+
<option value="mixed">Mixed Chart</option>
|
| 165 |
+
</select>
|
| 166 |
+
</div>
|
| 167 |
+
<div class="mb-3">
|
| 168 |
+
<label for="tableDataInput" class="form-label">Tabular Data (Markdown):</label>
|
| 169 |
+
<textarea id="tableDataInput" rows="6" class="form-control" placeholder="Paste your data here...">| Year | Profit (in lakhs) | Revenue (in crores) | Expenses (in lakhs) |
|
| 170 |
|-------|------------------|---------------------|---------------------|
|
| 171 |
| Year 1 | 80 | 10 | 50 |
|
| 172 |
| Year 2 | 90 | 15 | 60 |
|
| 173 |
| Year 3 | 85 | 13 | 55 |
|
| 174 |
| Year 4 | 95 | 18 | 70 |
|
| 175 |
+
| Year 5 | 100 | 20 | 80 |</textarea>
|
| 176 |
+
</div>
|
| 177 |
+
<div class="mt-3 text-center">
|
| 178 |
+
<button onclick="generateChart()" class="btn btn-primary">Generate Chart</button>
|
| 179 |
+
</div>
|
| 180 |
</div>
|
| 181 |
</div>
|
| 182 |
+
<!-- Parsed Table Data (Read-Only) Card -->
|
| 183 |
+
<div class="card mb-3">
|
| 184 |
+
<div class="card-header">Parsed Table Data (Read-Only)</div>
|
| 185 |
+
<div class="card-body" id="tableContainer">
|
| 186 |
+
<!-- Generated table will appear here -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
</div>
|
| 188 |
</div>
|
| 189 |
+
<!-- Customize Row Colors Card -->
|
| 190 |
+
<div class="card mb-3">
|
| 191 |
+
<div class="card-header">Customize Row Colors</div>
|
| 192 |
+
<div class="card-body" id="rowColorPickers">
|
| 193 |
+
<!-- Row color pickers generated here -->
|
|
|
|
|
|
|
|
|
|
| 194 |
</div>
|
| 195 |
</div>
|
| 196 |
+
<!-- Customize Column Colors Card -->
|
| 197 |
+
<div class="card mb-3">
|
| 198 |
+
<div class="card-header">Customize Column Colors</div>
|
| 199 |
+
<div class="card-body" id="colColorPickers">
|
| 200 |
+
<!-- Column color pickers generated here -->
|
| 201 |
+
</div>
|
| 202 |
</div>
|
| 203 |
</div>
|
|
|
|
| 204 |
|
| 205 |
+
<!-- Middle Column -->
|
| 206 |
+
<div class="col-lg-6 col-md-4 col-desktop">
|
| 207 |
+
<!-- Chart Display Card -->
|
| 208 |
+
<div class="card mb-3">
|
| 209 |
+
<div class="card-header">Chart</div>
|
| 210 |
+
<div class="card-body">
|
| 211 |
+
<div class="chart-container">
|
| 212 |
+
<canvas id="myChart"></canvas>
|
| 213 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
</div>
|
| 215 |
</div>
|
| 216 |
+
<!-- Button Area Below Chart -->
|
| 217 |
+
<div class="text-center mb-3">
|
| 218 |
+
<button onclick="downloadChart('png')" class="btn btn-success me-2">Download PNG</button>
|
| 219 |
+
<button onclick="downloadChart('jpeg')" class="btn btn-success me-2">Download JPG</button>
|
| 220 |
+
<button onclick="copyChartToClipboard()" class="btn btn-warning me-2">Copy to Clipboard</button>
|
| 221 |
+
</div>
|
| 222 |
+
<!-- Sponsored Card -->
|
| 223 |
+
<div class="card">
|
| 224 |
+
<div class="card-header">Sponsored</div>
|
| 225 |
+
<div class="card-body ad-container">
|
| 226 |
+
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2810665891608163" crossorigin="anonymous"></script>
|
| 227 |
+
<ins class="adsbygoogle"
|
| 228 |
+
style="display:block"
|
| 229 |
+
data-ad-client="ca-pub-2810665891608163"
|
| 230 |
+
data-ad-slot="8588732226"
|
| 231 |
+
data-ad-format="auto"
|
| 232 |
+
data-full-width-responsive="true"></ins>
|
| 233 |
+
<script>
|
| 234 |
+
(adsbygoogle = window.adsbygoogle || []).push({});
|
| 235 |
+
</script>
|
| 236 |
</div>
|
| 237 |
</div>
|
| 238 |
</div>
|
|
|
|
| 239 |
|
| 240 |
+
<!-- Right Sidebar -->
|
| 241 |
+
<div class="col-lg-3 col-md-4 col-desktop">
|
| 242 |
+
<!-- Advanced Chart Options Card -->
|
| 243 |
+
<div class="card mb-3">
|
| 244 |
+
<div class="card-header">Advanced Chart Options</div>
|
| 245 |
+
<div class="card-body">
|
| 246 |
+
<div class="mb-3">
|
| 247 |
+
<label for="chartTitle" class="form-label">Chart Title:</label>
|
| 248 |
+
<input type="text" id="chartTitle" class="form-control" placeholder="Enter chart title" />
|
| 249 |
+
</div>
|
| 250 |
+
<div class="mb-3">
|
| 251 |
+
<label for="xAxisLabel" class="form-label">X Axis Label:</label>
|
| 252 |
+
<input type="text" id="xAxisLabel" class="form-control" placeholder="Enter X axis label" />
|
| 253 |
+
</div>
|
| 254 |
+
<div class="mb-3">
|
| 255 |
+
<label for="yAxisLabel" class="form-label">Y Axis Label:</label>
|
| 256 |
+
<input type="text" id="yAxisLabel" class="form-control" placeholder="Enter Y axis label" />
|
| 257 |
+
</div>
|
| 258 |
+
<div class="form-check mb-2">
|
| 259 |
+
<input type="checkbox" id="toggleLegend" class="form-check-input" checked>
|
| 260 |
+
<label for="toggleLegend" class="form-check-label">Show Legend</label>
|
| 261 |
+
</div>
|
| 262 |
+
<div class="form-check mb-2">
|
| 263 |
+
<input type="checkbox" id="toggleGrid" class="form-check-input" checked>
|
| 264 |
+
<label for="toggleGrid" class="form-check-label">Show Gridlines</label>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="mb-3">
|
| 267 |
+
<label for="legendPosition" class="form-label">Legend Position:</label>
|
| 268 |
+
<select id="legendPosition" class="form-select">
|
| 269 |
+
<option value="top" selected>Top</option>
|
| 270 |
+
<option value="bottom">Bottom</option>
|
| 271 |
+
<option value="left">Left</option>
|
| 272 |
+
<option value="right">Right</option>
|
| 273 |
+
</select>
|
| 274 |
+
</div>
|
| 275 |
</div>
|
| 276 |
</div>
|
| 277 |
+
<!-- Watermark Options Card -->
|
| 278 |
+
<div class="card mb-3">
|
| 279 |
+
<div class="card-header">Watermark Options</div>
|
| 280 |
+
<div class="card-body">
|
| 281 |
+
<div class="mb-3">
|
| 282 |
+
<label for="watermarkText" class="form-label">Watermark Text:</label>
|
| 283 |
+
<input type="text" id="watermarkText" class="form-control" value="examups.com" />
|
| 284 |
+
</div>
|
| 285 |
+
<div class="mb-3">
|
| 286 |
+
<label for="watermarkOpacity" class="form-label">Opacity (0-1):</label>
|
| 287 |
+
<input type="number" id="watermarkOpacity" class="form-control" step="0.1" min="0" max="1" value="0.5" />
|
| 288 |
+
</div>
|
| 289 |
+
<div class="mb-3">
|
| 290 |
+
<label for="watermarkFontSize" class="form-label">Font Size (px):</label>
|
| 291 |
+
<input type="number" id="watermarkFontSize" class="form-control" value="20" />
|
| 292 |
+
</div>
|
| 293 |
+
<div class="mb-3">
|
| 294 |
+
<label for="watermarkPosition" class="form-label">Position:</label>
|
| 295 |
+
<select id="watermarkPosition" class="form-select">
|
| 296 |
+
<option value="center" selected>Center</option>
|
| 297 |
+
<option value="top-left">Top Left</option>
|
| 298 |
+
<option value="top-right">Top Right</option>
|
| 299 |
+
<option value="bottom-left">Bottom Left</option>
|
| 300 |
+
<option value="bottom-right">Bottom Right</option>
|
| 301 |
+
</select>
|
| 302 |
+
</div>
|
| 303 |
+
<div class="mb-3">
|
| 304 |
+
<label for="watermarkImage" class="form-label">Upload Image (Optional):</label>
|
| 305 |
+
<input type="file" id="watermarkImage" class="form-control" accept="image/*" />
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
</div>
|
| 309 |
+
<!-- Additional Customizations Card -->
|
| 310 |
+
<div class="card mb-3">
|
| 311 |
+
<div class="card-header">Additional Customizations</div>
|
| 312 |
+
<div class="card-body">
|
| 313 |
+
<div class="row g-3">
|
| 314 |
+
<div class="col-12 mb-3">
|
| 315 |
+
<label for="colorTheme" class="form-label">Color Theme:</label>
|
| 316 |
+
<select id="colorTheme" class="form-select">
|
| 317 |
+
<option value="default" selected>Default</option>
|
| 318 |
+
<option value="pastel">Pastel</option>
|
| 319 |
+
<option value="vibrant">Vibrant</option>
|
| 320 |
+
<option value="dark">Dark</option>
|
| 321 |
+
</select>
|
| 322 |
+
</div>
|
| 323 |
+
<div class="col-6 mb-3">
|
| 324 |
+
<label for="gridColor" class="form-label">Grid Color:</label>
|
| 325 |
+
<input type="color" id="gridColor" class="form-control form-control-color" value="#e9ecef" />
|
| 326 |
+
</div>
|
| 327 |
+
<div class="col-6 mb-3">
|
| 328 |
+
<label for="tooltipBgColor" class="form-label">Tooltip BG Color:</label>
|
| 329 |
+
<input type="color" id="tooltipBgColor" class="form-control form-control-color" value="#000000" />
|
| 330 |
+
</div>
|
| 331 |
+
<div class="col-6 mb-3">
|
| 332 |
+
<label for="titleFontFamily" class="form-label">Title Font:</label>
|
| 333 |
+
<input type="text" id="titleFontFamily" class="form-control" value="Arial" />
|
| 334 |
+
</div>
|
| 335 |
+
<div class="col-6 mb-3">
|
| 336 |
+
<label for="titleFontSize" class="form-label">Title Size (px):</label>
|
| 337 |
+
<input type="number" id="titleFontSize" class="form-control" value="18" />
|
| 338 |
+
</div>
|
| 339 |
+
<div class="col-6 mb-3">
|
| 340 |
+
<label for="chartBgColor" class="form-label">Chart Background:</label>
|
| 341 |
+
<input type="color" id="chartBgColor" class="form-control form-control-color" value="#ffffff" />
|
| 342 |
+
</div>
|
| 343 |
+
<div class="col-6 mb-3">
|
| 344 |
+
<label for="chartBorderColor" class="form-label">Chart Border Color:</label>
|
| 345 |
+
<input type="color" id="chartBorderColor" class="form-control form-control-color" value="#cccccc" />
|
| 346 |
+
</div>
|
| 347 |
+
<div class="col-12 form-check">
|
| 348 |
+
<input type="checkbox" id="showAnnotations" class="form-check-input" checked>
|
| 349 |
+
<label for="showAnnotations" class="form-check-label">Show Data Annotations</label>
|
| 350 |
+
</div>
|
| 351 |
+
</div>
|
| 352 |
+
<div class="text-center">
|
| 353 |
+
<button onclick="updateCustomizations()" class="btn btn-primary">Apply Customizations</button>
|
| 354 |
+
</div>
|
| 355 |
+
</div>
|
| 356 |
</div>
|
| 357 |
</div>
|
| 358 |
</div>
|
| 359 |
</div>
|
| 360 |
|
| 361 |
+
<!-- Right after main content, no footer area -->
|
| 362 |
+
|
| 363 |
+
<!-- Top Footer Google Ad remains at the bottom -->
|
| 364 |
<div class="ad-container">
|
| 365 |
+
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2810665891608163" crossorigin="anonymous"></script>
|
|
|
|
|
|
|
| 366 |
<ins class="adsbygoogle"
|
| 367 |
style="display:block"
|
| 368 |
data-ad-client="ca-pub-2810665891608163"
|
|
|
|
| 370 |
data-ad-format="auto"
|
| 371 |
data-full-width-responsive="true"></ins>
|
| 372 |
<script>
|
| 373 |
+
(adsbygoogle = window.adsbygoogle || []).push({});
|
| 374 |
</script>
|
| 375 |
</div>
|
| 376 |
|
| 377 |
+
<!-- Scripts -->
|
| 378 |
<script>
|
| 379 |
let chartInstance = null;
|
| 380 |
let currentChartConfig = {};
|
| 381 |
+
let rowColors = [];
|
| 382 |
+
let colColors = [];
|
| 383 |
+
|
| 384 |
+
// Global variable for data annotations
|
| 385 |
+
let showAnnotations = document.getElementById("showAnnotations")?.checked || true;
|
| 386 |
+
|
| 387 |
+
// Custom Annotation Plugin (for non-pie charts)
|
| 388 |
+
const annotationPlugin = {
|
| 389 |
+
id: 'annotationPlugin',
|
| 390 |
+
afterDatasetsDraw: (chart, args, options) => {
|
| 391 |
+
if (!options.showAnnotations) return;
|
| 392 |
+
const ctx = chart.ctx;
|
| 393 |
+
chart.data.datasets.forEach((dataset, datasetIndex) => {
|
| 394 |
+
const meta = chart.getDatasetMeta(datasetIndex);
|
| 395 |
+
meta.data.forEach((element, index) => {
|
| 396 |
+
const value = dataset.data[index];
|
| 397 |
+
ctx.fillStyle = options.fontColor || 'white';
|
| 398 |
+
ctx.font = `${options.fontSize || 12}px ${options.fontFamily || 'Arial'}`;
|
| 399 |
+
ctx.textAlign = 'center';
|
| 400 |
+
ctx.textBaseline = 'bottom';
|
| 401 |
+
ctx.fillText(value, element.x, element.y - 5);
|
| 402 |
+
});
|
| 403 |
+
});
|
| 404 |
+
}
|
| 405 |
+
};
|
| 406 |
+
Chart.register(annotationPlugin);
|
| 407 |
|
| 408 |
+
// Helper: Blend two hex colors (50/50 average).
|
| 409 |
function blendColors(c1, c2) {
|
| 410 |
const r1 = parseInt(c1.slice(1, 3), 16);
|
| 411 |
const g1 = parseInt(c1.slice(3, 5), 16);
|
|
|
|
| 419 |
return "#" + [r, g, b].map(x => x.toString(16).padStart(2, "0")).join("");
|
| 420 |
}
|
| 421 |
|
| 422 |
+
// Parse table data from markdown table.
|
| 423 |
function parseTableData(input) {
|
| 424 |
const rows = input.trim().split("\n");
|
| 425 |
+
const headers = rows[0].split("|").map(h => h.trim()).filter(h => h);
|
| 426 |
const labels = [];
|
| 427 |
const datasets = headers.slice(1).map(header => ({
|
| 428 |
label: header,
|
| 429 |
data: [],
|
| 430 |
borderColor: "#333",
|
| 431 |
+
borderWidth: 1
|
| 432 |
}));
|
| 433 |
for (let i = 2; i < rows.length; i++) {
|
| 434 |
+
const cells = rows[i].split("|").map(cell => cell.trim()).filter(cell => cell);
|
| 435 |
if (cells.length === headers.length) {
|
| 436 |
labels.push(cells[0]);
|
| 437 |
for (let j = 1; j < cells.length; j++) {
|
|
|
|
| 465 |
|
| 466 |
// Generate HTML table for parsed data.
|
| 467 |
function generateTable(headers, labels, datasets) {
|
| 468 |
+
let html = `<div class="table-responsive"><table class="table table-bordered"><thead class="table-light"><tr>`;
|
| 469 |
+
headers.forEach(h => { html += `<th>${h}</th>`; });
|
| 470 |
+
html += `</tr></thead><tbody>`;
|
| 471 |
for (let i = 0; i < labels.length; i++) {
|
| 472 |
+
html += `<tr><td>${labels[i]}</td>`;
|
| 473 |
+
datasets.forEach(ds => { html += `<td>${ds.data[i]}</td>`; });
|
| 474 |
+
html += `</tr>`;
|
| 475 |
}
|
| 476 |
+
html += `</tbody></table></div>`;
|
| 477 |
+
document.getElementById("tableContainer").innerHTML = html;
|
| 478 |
}
|
| 479 |
|
| 480 |
// Generate the chart using Chart.js.
|
| 481 |
function generateChart() {
|
| 482 |
const chartType = document.getElementById("chartType").value;
|
| 483 |
+
const tableData = document.getElementById("tableDataInput").value;
|
| 484 |
+
const { headers, labels, datasets } = parseTableData(tableData);
|
| 485 |
|
| 486 |
// Initialize row and column colors.
|
| 487 |
rowColors = labels.map(() => getRandomColor());
|
| 488 |
colColors = datasets.map(() => getRandomColor());
|
|
|
|
|
|
|
| 489 |
updateCompositeColors(datasets, labels);
|
| 490 |
|
| 491 |
+
// Adjust for special chart types.
|
| 492 |
+
let finalType = chartType;
|
| 493 |
+
if (chartType === "area") {
|
| 494 |
+
finalType = "line";
|
| 495 |
+
datasets.forEach(ds => ds.fill = true);
|
| 496 |
+
} else if (chartType === "scatter") {
|
| 497 |
+
finalType = "scatter";
|
| 498 |
+
datasets.forEach(ds => {
|
| 499 |
+
ds.data = ds.data.map((v, i) => ({ x: i, y: v }));
|
| 500 |
+
});
|
| 501 |
+
} else if (chartType === "bubble") {
|
| 502 |
+
finalType = "bubble";
|
| 503 |
+
datasets.forEach(ds => {
|
| 504 |
+
ds.data = ds.data.map((v, i) => ({ x: i, y: v, r: 10 }));
|
| 505 |
+
});
|
| 506 |
+
} else if (chartType === "mixed") {
|
| 507 |
+
finalType = "bar";
|
| 508 |
+
datasets.forEach((ds, i) => { ds.type = (i % 2 === 0) ? "bar" : "line"; });
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
// Set click event for drill-down.
|
| 512 |
+
const onClickHandler = function(evt, activeElements) {
|
| 513 |
+
if (activeElements.length > 0) {
|
| 514 |
+
const element = activeElements[0];
|
| 515 |
+
const dsIndex = element.datasetIndex;
|
| 516 |
+
const index = element.index;
|
| 517 |
+
const label = this.data.labels[index];
|
| 518 |
+
const value = this.data.datasets[dsIndex].data[index];
|
| 519 |
+
alert(`Drill-down: ${label} - ${value}`);
|
| 520 |
+
}
|
| 521 |
+
};
|
| 522 |
+
|
| 523 |
if (chartInstance) { chartInstance.destroy(); }
|
| 524 |
generateTable(headers, labels, datasets);
|
|
|
|
| 525 |
const ctx = document.getElementById("myChart").getContext("2d");
|
| 526 |
chartInstance = new Chart(ctx, {
|
| 527 |
+
type: finalType,
|
| 528 |
+
data: { labels, datasets },
|
| 529 |
options: {
|
| 530 |
responsive: true,
|
| 531 |
maintainAspectRatio: false,
|
| 532 |
+
onClick: onClickHandler,
|
| 533 |
plugins: {
|
| 534 |
+
legend: { display: true, position: document.getElementById("legendPosition").value },
|
| 535 |
+
title: {
|
| 536 |
+
display: true,
|
| 537 |
+
text: `${headers[0]} vs Multiple Columns`,
|
| 538 |
+
font: { family: document.getElementById("titleFontFamily").value, size: parseInt(document.getElementById("titleFontSize").value) }
|
| 539 |
+
},
|
| 540 |
+
tooltip: { backgroundColor: document.getElementById("tooltipBgColor").value },
|
| 541 |
+
annotationPlugin: {
|
| 542 |
+
showAnnotations: document.getElementById("showAnnotations").checked,
|
| 543 |
+
fontColor: "white",
|
| 544 |
+
fontSize: parseInt(document.getElementById("titleFontSize").value),
|
| 545 |
+
fontFamily: document.getElementById("titleFontFamily").value
|
| 546 |
+
},
|
| 547 |
+
zoom: {
|
| 548 |
+
pan: { enabled: true, mode: 'xy' },
|
| 549 |
+
zoom: { wheel: { enabled: true }, pinch: { enabled: true }, mode: 'xy' }
|
| 550 |
+
}
|
| 551 |
},
|
| 552 |
scales: {
|
| 553 |
+
x: { grid: { display: true, color: document.getElementById("gridColor").value }, title: { display: false } },
|
| 554 |
+
y: { grid: { display: true, color: document.getElementById("gridColor").value }, title: { display: false } }
|
| 555 |
}
|
| 556 |
+
}
|
| 557 |
});
|
| 558 |
+
|
| 559 |
+
// Set chart background and border.
|
| 560 |
+
document.getElementById("myChart").style.backgroundColor = document.getElementById("chartBgColor").value;
|
| 561 |
+
document.getElementById("myChart").style.border = "2px solid " + document.getElementById("chartBorderColor").value;
|
| 562 |
+
|
| 563 |
+
currentChartConfig = { type: finalType, data: { labels, datasets }, options: chartInstance.options };
|
| 564 |
generateRowColorPickers(labels);
|
| 565 |
generateColColorPickers(datasets);
|
| 566 |
}
|
|
|
|
| 570 |
const container = document.getElementById("rowColorPickers");
|
| 571 |
container.innerHTML = "";
|
| 572 |
labels.forEach((label, index) => {
|
| 573 |
+
const div = document.createElement("div");
|
| 574 |
+
div.className = "color-picker-container";
|
| 575 |
+
div.innerHTML = `<label for="rowColor${index}">${label}</label>
|
| 576 |
+
<input type="color" id="rowColor${index}" class="form-control form-control-color" value="${rowColors[index]}" onchange="updateRowColor(${index}, this.value)">`;
|
| 577 |
+
container.appendChild(div);
|
|
|
|
|
|
|
| 578 |
});
|
| 579 |
}
|
| 580 |
|
|
|
|
| 582 |
function generateColColorPickers(datasets) {
|
| 583 |
const container = document.getElementById("colColorPickers");
|
| 584 |
container.innerHTML = "";
|
| 585 |
+
datasets.forEach((ds, index) => {
|
| 586 |
+
const div = document.createElement("div");
|
| 587 |
+
div.className = "color-picker-container";
|
| 588 |
+
div.innerHTML = `<label for="colColor${index}">${ds.label}</label>
|
| 589 |
+
<input type="color" id="colColor${index}" class="form-control form-control-color" value="${colColors[index]}" onchange="updateColColor(${index}, this.value)">`;
|
| 590 |
+
container.appendChild(div);
|
|
|
|
|
|
|
| 591 |
});
|
| 592 |
}
|
| 593 |
|
|
|
|
| 594 |
function updateRowColor(index, color) {
|
| 595 |
rowColors[index] = color;
|
| 596 |
+
chartInstance.data.datasets.forEach((ds, dIndex) => {
|
| 597 |
+
ds.backgroundColor[index] = blendColors(rowColors[index], colColors[dIndex]);
|
| 598 |
});
|
| 599 |
chartInstance.update();
|
| 600 |
}
|
| 601 |
|
|
|
|
| 602 |
function updateColColor(index, color) {
|
| 603 |
colColors[index] = color;
|
| 604 |
chartInstance.data.datasets[index].backgroundColor =
|
|
|
|
| 606 |
chartInstance.update();
|
| 607 |
}
|
| 608 |
|
|
|
|
| 609 |
function updateChartOptions() {
|
| 610 |
const newTitle = document.getElementById("chartTitle").value;
|
| 611 |
+
const newX = document.getElementById("xAxisLabel").value;
|
| 612 |
+
const newY = document.getElementById("yAxisLabel").value;
|
| 613 |
const showLegend = document.getElementById("toggleLegend").checked;
|
| 614 |
const showGrid = document.getElementById("toggleGrid").checked;
|
| 615 |
+
if (chartInstance.options.plugins.title) {
|
|
|
|
| 616 |
chartInstance.options.plugins.title.text = newTitle || chartInstance.options.plugins.title.text;
|
| 617 |
}
|
| 618 |
+
if (chartInstance.options.scales.x) {
|
| 619 |
+
chartInstance.options.scales.x.title = { display: newX ? true : false, text: newX };
|
|
|
|
|
|
|
|
|
|
| 620 |
chartInstance.options.scales.x.grid.display = showGrid;
|
| 621 |
}
|
| 622 |
+
if (chartInstance.options.scales.y) {
|
| 623 |
+
chartInstance.options.scales.y.title = { display: newY ? true : false, text: newY };
|
|
|
|
|
|
|
|
|
|
| 624 |
chartInstance.options.scales.y.grid.display = showGrid;
|
| 625 |
}
|
| 626 |
chartInstance.options.plugins.legend.display = showLegend;
|
| 627 |
+
chartInstance.options.plugins.legend.position = document.getElementById("legendPosition").value;
|
| 628 |
+
chartInstance.options.plugins.tooltip.backgroundColor = document.getElementById("tooltipBgColor").value;
|
| 629 |
+
chartInstance.options.scales.x.grid.color = document.getElementById("gridColor").value;
|
| 630 |
+
chartInstance.options.scales.y.grid.color = document.getElementById("gridColor").value;
|
| 631 |
+
chartInstance.options.plugins.title.font = {
|
| 632 |
+
family: document.getElementById("titleFontFamily").value,
|
| 633 |
+
size: parseInt(document.getElementById("titleFontSize").value)
|
| 634 |
+
};
|
| 635 |
chartInstance.update();
|
| 636 |
currentChartConfig.options = chartInstance.options;
|
| 637 |
}
|
| 638 |
|
| 639 |
+
function updateCustomizations() {
|
| 640 |
+
updateChartOptions();
|
| 641 |
+
const theme = document.getElementById("colorTheme").value;
|
| 642 |
+
if (theme !== "default") {
|
| 643 |
+
let preset;
|
| 644 |
+
if (theme === "pastel") {
|
| 645 |
+
preset = ["#A8D5BA", "#F9E79F", "#FAD7A0", "#D2B4DE"];
|
| 646 |
+
} else if (theme === "vibrant") {
|
| 647 |
+
preset = ["#FF5733", "#33FF57", "#3357FF", "#FF33A6"];
|
| 648 |
+
} else if (theme === "dark") {
|
| 649 |
+
preset = ["#555555", "#666666", "#777777", "#888888"];
|
| 650 |
+
}
|
| 651 |
+
rowColors = rowColors.map((_, i) => preset[i % preset.length]);
|
| 652 |
+
colColors = colColors.map((_, i) => preset[i % preset.length]);
|
| 653 |
+
const { labels, datasets } = currentChartConfig.data;
|
| 654 |
+
updateCompositeColors(datasets, labels);
|
| 655 |
+
chartInstance.update();
|
|
|
|
|
|
|
| 656 |
}
|
| 657 |
+
document.getElementById("myChart").style.backgroundColor = document.getElementById("chartBgColor").value;
|
| 658 |
+
document.getElementById("myChart").style.border = "2px solid " + document.getElementById("chartBorderColor").value;
|
| 659 |
}
|
| 660 |
|
| 661 |
+
// Draw tooltips for pie/doughnut charts in white.
|
| 662 |
function drawPieTooltips(ctx) {
|
| 663 |
if (chartInstance.config.type === "pie" || chartInstance.config.type === "doughnut") {
|
| 664 |
const meta = chartInstance.getDatasetMeta(0);
|
| 665 |
+
const ds = chartInstance.data.datasets[0];
|
| 666 |
+
const total = ds.data.reduce((s, v) => s + v, 0);
|
| 667 |
meta.data.forEach((arc, index) => {
|
| 668 |
const pos = arc.tooltipPosition();
|
| 669 |
+
const percentage = ((ds.data[index] / total) * 100).toFixed(1) + "%";
|
| 670 |
+
ctx.fillStyle = "white";
|
|
|
|
| 671 |
ctx.font = "bold 12px Arial";
|
| 672 |
ctx.textAlign = "center";
|
| 673 |
ctx.textBaseline = "middle";
|
|
|
|
| 676 |
}
|
| 677 |
}
|
| 678 |
|
| 679 |
+
// Compute watermark coordinates.
|
| 680 |
+
function getWatermarkCoordinates(width, height, position, wmWidth) {
|
| 681 |
+
let x, y;
|
| 682 |
+
switch (position) {
|
| 683 |
+
case "top-left": x = 10 + wmWidth / 2; y = 10; break;
|
| 684 |
+
case "top-right": x = width - 10 - wmWidth / 2; y = 10; break;
|
| 685 |
+
case "bottom-left": x = 10 + wmWidth / 2; y = height - 10; break;
|
| 686 |
+
case "bottom-right": x = width - 10 - wmWidth / 2; y = height - 10; break;
|
| 687 |
+
default: x = width / 2; y = height / 2; break;
|
| 688 |
+
}
|
| 689 |
+
return { x, y };
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
// Export high-quality image by scaling offscreen canvas.
|
| 693 |
function downloadChart(format) {
|
| 694 |
+
const origCanvas = document.getElementById("myChart");
|
| 695 |
+
const scaleFactor = window.devicePixelRatio || 2;
|
| 696 |
+
const offCanvas = document.createElement("canvas");
|
| 697 |
+
offCanvas.width = origCanvas.width * scaleFactor;
|
| 698 |
+
offCanvas.height = origCanvas.height * scaleFactor;
|
| 699 |
+
const offCtx = offCanvas.getContext("2d");
|
| 700 |
+
offCtx.scale(scaleFactor, scaleFactor);
|
| 701 |
if (format === "jpeg") {
|
| 702 |
offCtx.fillStyle = "white";
|
| 703 |
+
offCtx.fillRect(0, 0, origCanvas.width, origCanvas.height);
|
| 704 |
}
|
| 705 |
+
offCtx.drawImage(origCanvas, 0, 0);
|
|
|
|
|
|
|
| 706 |
if (chartInstance.config.type === "pie" || chartInstance.config.type === "doughnut") {
|
| 707 |
drawPieTooltips(offCtx);
|
| 708 |
}
|
| 709 |
+
const watermarkImage = document.getElementById("watermarkImage");
|
| 710 |
+
const wmOpacity = document.getElementById("watermarkOpacity").value;
|
| 711 |
+
const wmPos = document.getElementById("watermarkPosition").value;
|
| 712 |
+
const wmFontSize = document.getElementById("watermarkFontSize").value;
|
| 713 |
+
offCtx.font = `${wmFontSize}px Arial`;
|
| 714 |
+
offCtx.fillStyle = `rgba(255,165,0,${wmOpacity})`;
|
| 715 |
+
let textAlign = "center", textBaseline = "middle";
|
| 716 |
+
if (wmPos.includes("left")) textAlign = "left"; else if (wmPos.includes("right")) textAlign = "right";
|
| 717 |
+
if (wmPos.includes("top")) textBaseline = "top"; else if (wmPos.includes("bottom")) textBaseline = "bottom";
|
| 718 |
+
offCtx.textAlign = textAlign;
|
| 719 |
+
offCtx.textBaseline = textBaseline;
|
| 720 |
+
const coords = getWatermarkCoordinates(origCanvas.width, origCanvas.height, wmPos, parseInt(wmFontSize));
|
| 721 |
+
if (watermarkImage.files && watermarkImage.files[0]) {
|
| 722 |
const reader = new FileReader();
|
| 723 |
+
reader.onload = function (e) {
|
| 724 |
+
const img = new Image();
|
| 725 |
+
img.onload = function () {
|
| 726 |
+
offCtx.globalAlpha = parseFloat(wmOpacity);
|
| 727 |
+
offCtx.drawImage(img, coords.x - img.width / 2, coords.y - img.height / 2);
|
|
|
|
| 728 |
offCtx.globalAlpha = 1.0;
|
| 729 |
+
let fName = document.getElementById("chartFileName").value || "chart";
|
| 730 |
const link = document.createElement("a");
|
| 731 |
+
link.download = `${fName}.${format}`;
|
| 732 |
+
link.href = offCanvas.toDataURL(`image/${format}`);
|
| 733 |
link.click();
|
| 734 |
}
|
| 735 |
+
img.src = e.target.result;
|
| 736 |
}
|
| 737 |
+
reader.readAsDataURL(watermarkImage.files[0]);
|
| 738 |
} else {
|
| 739 |
+
offCtx.fillText(document.getElementById("watermarkText").value, coords.x, coords.y);
|
| 740 |
+
let fName = document.getElementById("chartFileName").value || "chart";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 741 |
const link = document.createElement("a");
|
| 742 |
+
link.download = `${fName}.${format}`;
|
| 743 |
+
link.href = offCanvas.toDataURL(`image/${format}`);
|
| 744 |
link.click();
|
| 745 |
}
|
| 746 |
}
|
| 747 |
|
| 748 |
+
// Download as SVG.
|
| 749 |
+
function downloadSVG() {
|
| 750 |
+
const origCanvas = document.getElementById("myChart");
|
| 751 |
+
const width = origCanvas.width, height = origCanvas.height;
|
| 752 |
+
const svgCtx = new C2S(width, height);
|
| 753 |
+
new Chart(svgCtx, currentChartConfig);
|
| 754 |
+
const svgData = svgCtx.getSerializedSvg();
|
| 755 |
+
const blob = new Blob([svgData], { type: "image/svg+xml;charset=utf-8" });
|
| 756 |
+
let fName = document.getElementById("chartFileName").value || "chart";
|
| 757 |
+
const link = document.createElement("a");
|
| 758 |
+
link.href = URL.createObjectURL(blob);
|
| 759 |
+
link.download = `${fName}.svg`;
|
| 760 |
+
link.click();
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
// Download as PDF.
|
| 764 |
+
async function downloadPDF() {
|
| 765 |
+
const canvas = document.getElementById("myChart");
|
| 766 |
+
const scaleFactor = window.devicePixelRatio || 2;
|
| 767 |
+
const offCanvas = document.createElement("canvas");
|
| 768 |
+
offCanvas.width = canvas.width * scaleFactor;
|
| 769 |
+
offCanvas.height = canvas.height * scaleFactor;
|
| 770 |
+
const offCtx = offCanvas.getContext("2d");
|
| 771 |
+
offCtx.scale(scaleFactor, scaleFactor);
|
| 772 |
+
offCtx.drawImage(canvas, 0, 0);
|
| 773 |
+
const imgData = offCanvas.toDataURL("image/png");
|
| 774 |
+
const { jsPDF } = window.jspdf;
|
| 775 |
+
const pdf = new jsPDF("landscape");
|
| 776 |
+
const pdfWidth = pdf.internal.pageSize.getWidth();
|
| 777 |
+
const pdfHeight = pdf.internal.pageSize.getHeight();
|
| 778 |
+
pdf.addImage(imgData, "PNG", 10, 10, pdfWidth - 20, pdfHeight - 20);
|
| 779 |
+
let fName = document.getElementById("chartFileName").value || "chart";
|
| 780 |
+
pdf.save(`${fName}.pdf`);
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
// Copy chart to clipboard (PNG).
|
| 784 |
async function copyChartToClipboard() {
|
| 785 |
+
const origCanvas = document.getElementById("myChart");
|
| 786 |
+
const scaleFactor = window.devicePixelRatio || 2;
|
| 787 |
+
const offCanvas = document.createElement("canvas");
|
| 788 |
+
offCanvas.width = origCanvas.width * scaleFactor;
|
| 789 |
+
offCanvas.height = origCanvas.height * scaleFactor;
|
| 790 |
+
const offCtx = offCanvas.getContext("2d");
|
| 791 |
+
offCtx.scale(scaleFactor, scaleFactor);
|
| 792 |
+
offCtx.drawImage(origCanvas, 0, 0);
|
| 793 |
if (chartInstance.config.type === "pie" || chartInstance.config.type === "doughnut") {
|
| 794 |
drawPieTooltips(offCtx);
|
| 795 |
}
|
| 796 |
+
const watermarkImage = document.getElementById("watermarkImage");
|
| 797 |
+
const wmOpacity = document.getElementById("watermarkOpacity").value;
|
| 798 |
+
const wmPos = document.getElementById("watermarkPosition").value;
|
| 799 |
+
const wmFontSize = document.getElementById("watermarkFontSize").value;
|
| 800 |
+
offCtx.font = `${wmFontSize}px Arial`;
|
| 801 |
+
offCtx.fillStyle = `rgba(255,165,0,${wmOpacity})`;
|
| 802 |
+
let textAlign = "center", textBaseline = "middle";
|
| 803 |
+
if (wmPos.includes("left")) textAlign = "left"; else if (wmPos.includes("right")) textAlign = "right";
|
| 804 |
+
if (wmPos.includes("top")) textBaseline = "top"; else if (wmPos.includes("bottom")) textBaseline = "bottom";
|
| 805 |
+
offCtx.textAlign = textAlign;
|
| 806 |
+
offCtx.textBaseline = textBaseline;
|
| 807 |
+
const coords = getWatermarkCoordinates(origCanvas.width, origCanvas.height, wmPos, parseInt(wmFontSize));
|
| 808 |
+
if (watermarkImage.files && watermarkImage.files[0]) {
|
| 809 |
const reader = new FileReader();
|
| 810 |
+
reader.onload = function (e) {
|
| 811 |
+
const img = new Image();
|
| 812 |
+
img.onload = function () {
|
| 813 |
+
offCtx.globalAlpha = parseFloat(wmOpacity);
|
| 814 |
+
offCtx.drawImage(img, coords.x - img.width / 2, coords.y - img.height / 2);
|
|
|
|
| 815 |
offCtx.globalAlpha = 1.0;
|
| 816 |
+
offCanvas.toBlob(blob => {
|
| 817 |
const item = new ClipboardItem({ "image/png": blob });
|
| 818 |
navigator.clipboard.write([item])
|
| 819 |
+
.then(() => alert("Chart copied with watermark!"))
|
| 820 |
+
.catch(err => alert("Error copying: " + err));
|
| 821 |
}, "image/png");
|
| 822 |
}
|
| 823 |
+
img.src = e.target.result;
|
| 824 |
}
|
| 825 |
+
reader.readAsDataURL(watermarkImage.files[0]);
|
| 826 |
} else {
|
| 827 |
+
offCtx.fillText(document.getElementById("watermarkText").value, coords.x, coords.y);
|
| 828 |
+
offCanvas.toBlob(blob => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 829 |
const item = new ClipboardItem({ "image/png": blob });
|
| 830 |
navigator.clipboard.write([item])
|
| 831 |
+
.then(() => alert("Chart copied with watermark!"))
|
| 832 |
+
.catch(err => alert("Error copying: " + err));
|
| 833 |
}, "image/png");
|
| 834 |
}
|
| 835 |
}
|
| 836 |
|
| 837 |
+
// Export parsed data as CSV.
|
| 838 |
function exportDataAsCSV() {
|
| 839 |
+
const tableData = document.getElementById("tableDataInput").value;
|
| 840 |
+
const { headers, labels, datasets } = parseTableData(tableData);
|
| 841 |
+
let csv = headers.join(",") + "\n";
|
| 842 |
+
for (let i = 0; i < labels.length; i++) {
|
| 843 |
let row = [labels[i]];
|
| 844 |
+
datasets.forEach(ds => { row.push(ds.data[i]); });
|
| 845 |
+
csv += row.join(",") + "\n";
|
| 846 |
}
|
| 847 |
+
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
| 848 |
+
let fName = document.getElementById("chartFileName").value || "chart";
|
| 849 |
const link = document.createElement("a");
|
| 850 |
link.href = URL.createObjectURL(blob);
|
| 851 |
+
link.download = `${fName}.csv`;
|
| 852 |
link.click();
|
| 853 |
}
|
| 854 |
|
| 855 |
+
// Export chart configuration as JSON.
|
| 856 |
function exportChartConfigAsJSON() {
|
| 857 |
const jsonStr = JSON.stringify(currentChartConfig, null, 2);
|
| 858 |
const blob = new Blob([jsonStr], { type: 'application/json' });
|
| 859 |
+
let fName = document.getElementById("chartFileName").value || "chart";
|
| 860 |
const link = document.createElement("a");
|
| 861 |
link.href = URL.createObjectURL(blob);
|
| 862 |
+
link.download = `${fName}_config.json`;
|
| 863 |
link.click();
|
| 864 |
}
|
| 865 |
+
|
| 866 |
+
// Generate embed code.
|
| 867 |
+
function generateEmbedCode() {
|
| 868 |
+
const url = window.location.href;
|
| 869 |
+
const embed = `<iframe src="${url}" width="600" height="400" frameborder="0" scrolling="no"></iframe>`;
|
| 870 |
+
document.getElementById("embedCode").value = embed;
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
// Additional Customizations.
|
| 874 |
+
function updateCustomizations() {
|
| 875 |
+
updateChartOptions();
|
| 876 |
+
const theme = document.getElementById("colorTheme").value;
|
| 877 |
+
if (theme !== "default") {
|
| 878 |
+
let preset;
|
| 879 |
+
if (theme === "pastel") {
|
| 880 |
+
preset = ["#A8D5BA", "#F9E79F", "#FAD7A0", "#D2B4DE"];
|
| 881 |
+
} else if (theme === "vibrant") {
|
| 882 |
+
preset = ["#FF5733", "#33FF57", "#3357FF", "#FF33A6"];
|
| 883 |
+
} else if (theme === "dark") {
|
| 884 |
+
preset = ["#555555", "#666666", "#777777", "#888888"];
|
| 885 |
+
}
|
| 886 |
+
rowColors = rowColors.map((_, i) => preset[i % preset.length]);
|
| 887 |
+
colColors = colColors.map((_, i) => preset[i % preset.length]);
|
| 888 |
+
const { labels, datasets } = currentChartConfig.data;
|
| 889 |
+
updateCompositeColors(datasets, labels);
|
| 890 |
+
chartInstance.update();
|
| 891 |
+
}
|
| 892 |
+
document.getElementById("myChart").style.backgroundColor = document.getElementById("chartBgColor").value;
|
| 893 |
+
document.getElementById("myChart").style.border = "2px solid " + document.getElementById("chartBorderColor").value;
|
| 894 |
+
}
|
| 895 |
+
|
| 896 |
+
function updateChartOptions() {
|
| 897 |
+
const newTitle = document.getElementById("chartTitle").value;
|
| 898 |
+
const newX = document.getElementById("xAxisLabel").value;
|
| 899 |
+
const newY = document.getElementById("yAxisLabel").value;
|
| 900 |
+
const showLegend = document.getElementById("toggleLegend").checked;
|
| 901 |
+
const showGrid = document.getElementById("toggleGrid").checked;
|
| 902 |
+
if (chartInstance.options.plugins.title) {
|
| 903 |
+
chartInstance.options.plugins.title.text = newTitle || chartInstance.options.plugins.title.text;
|
| 904 |
+
}
|
| 905 |
+
if (chartInstance.options.scales.x) {
|
| 906 |
+
chartInstance.options.scales.x.title = { display: newX ? true : false, text: newX };
|
| 907 |
+
chartInstance.options.scales.x.grid.display = showGrid;
|
| 908 |
+
}
|
| 909 |
+
if (chartInstance.options.scales.y) {
|
| 910 |
+
chartInstance.options.scales.y.title = { display: newY ? true : false, text: newY };
|
| 911 |
+
chartInstance.options.scales.y.grid.display = showGrid;
|
| 912 |
+
}
|
| 913 |
+
chartInstance.options.plugins.legend.display = showLegend;
|
| 914 |
+
chartInstance.options.plugins.legend.position = document.getElementById("legendPosition").value;
|
| 915 |
+
chartInstance.options.plugins.tooltip.backgroundColor = document.getElementById("tooltipBgColor").value;
|
| 916 |
+
chartInstance.options.scales.x.grid.color = document.getElementById("gridColor").value;
|
| 917 |
+
chartInstance.options.scales.y.grid.color = document.getElementById("gridColor").value;
|
| 918 |
+
chartInstance.options.plugins.title.font = {
|
| 919 |
+
family: document.getElementById("titleFontFamily").value,
|
| 920 |
+
size: parseInt(document.getElementById("titleFontSize").value)
|
| 921 |
+
};
|
| 922 |
+
chartInstance.update();
|
| 923 |
+
currentChartConfig.options = chartInstance.options;
|
| 924 |
+
}
|
| 925 |
</script>
|
| 926 |
<!-- Bootstrap Bundle with Popper -->
|
| 927 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|