📅  最后修改于: 2023-12-03 15:28:17.220000             🧑  作者: Mango
轻量级图表 CDN 是一个基于 HTML 的图表库,可以帮助开发者快速地在网页中添加图表和图形。该库的特点是轻量便捷、易于使用和高度可定制化,同时还支持跨平台跨浏览器。
<script type="text/javascript" src="https://cdn.example.com/chart.js"></script>
<canvas id="myChart" width="400" height="400"></canvas>
<script type="text/javascript">
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
type: 'line',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'My First Dataset',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
data: [0, 10, 5, 2, 20, 30, 45]
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
</script>
<canvas id="myChart" width="400" height="400"></canvas>
<script type="text/javascript">
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
type: 'line',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'My First Dataset',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
data: [0, 10, 5, 2, 20, 30, 45]
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
</script>
<canvas id="myChart" width="400" height="400"></canvas>
<script type="text/javascript">
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'My First Dataset',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
data: [0, 10, 5, 2, 20, 30, 45]
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
</script>
<canvas id="myChart" width="400" height="400"></canvas>
<script type="text/javascript">
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
type: 'pie',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: 'My First Dataset',
backgroundColor: [
'#FF6384',
'#36A2EB',
'#FFCE56',
'#1ABC9C',
'#8E44AD',
'#F39C12'
],
data: [12, 19, 3, 5, 2, 3]
}]
},
options: {
responsive: true,
legend: {
position: 'bottom'
},
title: {
display: true,
text: 'My Pie Chart'
},
animation: {
animateScale: true,
animateRotate: true
}
}
});
</script>
backgroundColor
:背景颜色borderColor
:边框颜色hoverBackgroundColor
:鼠标悬停时的背景颜色hoverBorderColor
:鼠标悬停时的边框颜色fontColor
:字体颜色fontSize
:字体大小width
:宽度height
:高度轻量级图表 CDN 是一个方便、快捷、可定制化的图表库,支持多种图表类型和跨平台跨浏览器,开发者可以根据自己的需求进行使用和定制。