Last active
November 4, 2025 11:44
-
-
Save ritacse/2b8db8e8b28cf8d2e202ad572fecebc0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Link: https://www.chartjs.org/docs/latest/charts/bar.html | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>CM-wise Qty & Value Bar Chart</title> | |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels"></script> | |
| <style> | |
| body { | |
| font-family: Arial, sans-serif; | |
| margin: 20px; | |
| } | |
| .chart-container { | |
| position: relative; | |
| width: 100%; | |
| max-width: 900px; | |
| height: 450px; | |
| margin: auto; | |
| } | |
| @@media (max-width: 600px) { | |
| .chart-container { | |
| height: 320px; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="chart-container"> | |
| <canvas id="cmBarChart"></canvas> | |
| </div> | |
| <script> | |
| const ctx = document.getElementById('cmBarChart').getContext('2d'); | |
| const labels = ['CM01', 'CM02', 'CM03', 'CM04', 'CM05', 'CM06']; | |
| const qtyData = [120, 180, 90, 150, 200, 170]; | |
| const valueData = [24000, 36000, 18000, 30000, 40000, 35000]; | |
| new Chart(ctx, { | |
| type: 'bar', | |
| data: { | |
| labels: labels, | |
| datasets: [ | |
| { | |
| label: 'Quantity', | |
| data: qtyData, | |
| backgroundColor: 'rgba(54, 162, 235, 0.7)', | |
| borderColor: 'rgba(54, 162, 235, 1)', | |
| borderWidth: 1, | |
| borderRadius: 6, | |
| barThickness: 'flex' | |
| }, | |
| { | |
| label: 'Value', | |
| data: valueData, | |
| backgroundColor: 'rgba(255, 99, 132, 0.7)', | |
| borderColor: 'rgba(255, 99, 132, 1)', | |
| borderWidth: 1, | |
| borderRadius: 6, | |
| barThickness: 'flex' | |
| } | |
| ] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { position: 'bottom' }, | |
| title: { display: true, text: 'CM-wise Quantity & Value Comparison' }, | |
| datalabels: { | |
| anchor: 'end', | |
| align: 'top', | |
| color: '#111', | |
| font: { size: 11, weight: 'bold' }, | |
| formatter: (value) => value.toLocaleString() | |
| } | |
| }, | |
| interaction: { mode: 'index', intersect: false }, | |
| scales: { | |
| x: { | |
| title: { display: true, text: 'CM Code' }, | |
| ticks: { font: { size: 13 } } | |
| }, | |
| y: { | |
| beginAtZero: true, | |
| title: { display: true, text: 'Amount / Quantity' } | |
| } | |
| } | |
| }, | |
| plugins: [ChartDataLabels] | |
| }); | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Day-wise Qty & Value Line Chart</title> | |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels"></script> | |
| <style> | |
| body { | |
| font-family: Arial, sans-serif; | |
| margin: 20px; | |
| } | |
| .chart-container { | |
| position: relative; | |
| width: 100%; | |
| max-width: 900px; | |
| height: 450px; | |
| margin: auto; | |
| } | |
| @media (max-width: 600px) { | |
| .chart-container { | |
| height: 320px; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="chart-container"> | |
| <canvas id="dailyLineChart"></canvas> | |
| </div> | |
| <script> | |
| const ctx = document.getElementById('dailyLineChart').getContext('2d'); | |
| // Days of the month (1–31) | |
| const days = Array.from({ length: 31 }, (_, i) => Day ${i + 1}); | |
| // Example data | |
| const qtyData = [100, 120, 140, 130, 160, 180, 150, 190, 170, 200, 210, 190, 180, 220, 230, 250, 270, 260, 280, 300, 320, 310, 290, 270, 260, 280, 300, 310, 320, 340, 360]; | |
| const valueData = qtyData.map(q => q * 20); | |
| new Chart(ctx, { | |
| type: 'line', | |
| data: { | |
| labels: days, | |
| datasets: [ | |
| { | |
| label: 'Quantity', | |
| data: qtyData, | |
| borderColor: 'rgba(54, 162, 235, 1)', | |
| backgroundColor: 'rgba(54, 162, 235, 0.2)', | |
| tension: 0.4, | |
| fill: false, | |
| pointRadius: 4, | |
| pointHoverRadius: 6, | |
| pointBackgroundColor: 'rgba(54, 162, 235, 1)' | |
| }, | |
| { | |
| label: 'Value', | |
| data: valueData, | |
| borderColor: 'rgba(255, 99, 132, 1)', | |
| backgroundColor: 'rgba(255, 99, 132, 0.2)', | |
| tension: 0.4, | |
| fill: false, | |
| pointRadius: 4, | |
| pointHoverRadius: 6, | |
| pointBackgroundColor: 'rgba(255, 99, 132, 1)' | |
| } | |
| ] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { position: 'bottom' }, | |
| title: { | |
| display: true, | |
| text: 'Day-wise Quantity & Value Trend' | |
| }, | |
| datalabels: { | |
| align: 'top', | |
| anchor: 'end', | |
| color: '#111', | |
| font: { | |
| size: 11, | |
| weight: 'bold' | |
| }, | |
| formatter: function(value) { | |
| return value.toLocaleString(); | |
| } | |
| }, | |
| tooltip: { | |
| callbacks: { | |
| label: function(context) { | |
| return context.dataset.label + ': ' + context.formattedValue; | |
| } | |
| } | |
| } | |
| }, | |
| interaction: { mode: 'index', intersect: false }, | |
| scales: { | |
| x: { | |
| title: { display: true, text: 'Days of the Month' }, | |
| ticks: { font: { size: 12 } } | |
| }, | |
| y: { | |
| beginAtZero: true, | |
| title: { display: true, text: 'Quantity / Value' } | |
| } | |
| } | |
| }, | |
| plugins: [ChartDataLabels] | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment