<script src="https://www3.nhu.edu.tw/js/public/chart.js"></script>
<style>
#myChart {
width:600px;
margin: 20px auto;
}
@media screen and (max-width: 736px) {
#myChart {
width:400px;
height:600px !important;
}
}
</style>
<canvas id="myChart" ></canvas>
<script>const ctx = document.getElementById("myChart");
new Chart(ctx, {
type: "bar",
data: {
labels: ["台北", "台中", "高雄", "台南", "新竹"],
datasets: [{
label: "人口數 (萬)",
data: [260, 280, 190, 180, 120],
backgroundColor: "rgba(54, 162, 235, 0.7)",
borderColor: "rgba(54, 162, 235, 1)",
borderWidth: 1
}]
},
options: {
indexAxis: "y",
responsive: true,
scales: {
x: {
beginAtZero: true
}
}
}
});
</script>