Jul 2, 2024
chart
.index.html
for HTML content.style.css
for CSS styles.main.js
for JavaScript code.!
+ Tab
.<link rel="stylesheet" href="style.css">
.<script src="main.js"></script>
.<h2 class="chart-heading">Popular Programming Languages</h2>
.<div class="programming-stats">
.<div class="chart-container"><canvas class="my-chart"></canvas></div>
.<div class="details"><ul><li>Python: <span class="percentage">30%</span></li></ul></div>
.const myChart = document.querySelector('.my-chart');
new Chart(myChart, {
type: 'doughnut',
data: chartData,
options: { /* Customize chart options */ }
});
const chartData = {
labels: ['Python', 'Java', 'JavaScript', 'C#', 'Others'],
datasets: [{
label: 'Language Popularity',
data: [30, 17, 10, 7, 36],
backgroundColor: [/* Color list */],
}]
};
const populateUL = () => {
chartData.labels.forEach((l, i) => {
let li = document.createElement('li');
li.innerHTML = `${l}: <span class="percentage">${chartData.data[i]}%</span>`;
ul.appendChild(li);
});
}
.chart-heading
(font, color, text-transform, etc.).chart-container
(width, centering, etc.)options: {
plugins: {
legend: { display: false }
}
}