放射狀座標軸
放射狀座標軸特別用於雷達圖和極座標圖。這些軸會疊加在圖表區域上,而不是位於邊緣之一。Chart.js 中預設會包含一個放射狀軸。
視覺元件
放射狀軸是由可分別設定的視覺元件所組成。這些元件包括:
角度線
軸的格線會繪在圖表區域中。它們會自中心向畫布邊緣延伸。在以下範例中,它們為紅色。
const config = {
type: 'radar',
data,
options: {
scales: {
r: {
angleLines: {
color: 'red'
}
}
}
}
};
const labels = Utils.months({count: 7});
const data = {
labels: labels,
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgba(54, 162, 235, 0.5)',
borderColor: 'rgb(54, 162, 235)',
borderWidth: 1,
data: [10, 20, 30, 40, 50, 0, 5],
}]
};
格線
軸的格線會繪在圖表區域中。在以下範例中,它們為紅色。
const config = {
type: 'radar',
data,
options: {
scales: {
r: {
grid: {
color: 'red'
}
}
}
}
};
const labels = Utils.months({count: 7});
const data = {
labels: labels,
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgba(54, 162, 235, 0.5)',
borderColor: 'rgb(54, 162, 235)',
borderWidth: 1,
data: [10, 20, 30, 40, 50, 0, 5],
}]
};
點標籤
各點標籤會顯示各個角度線的值。在以下範例中,它們為紅色。
const config = {
type: 'radar',
data,
options: {
scales: {
r: {
pointLabels: {
color: 'red'
}
}
}
}
};
const labels = Utils.months({count: 7});
const data = {
labels: labels,
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgba(54, 162, 235, 0.5)',
borderColor: 'rgb(54, 162, 235)',
borderWidth: 1,
data: [10, 20, 30, 40, 50, 0, 5],
}]
};
刻度
刻度會根據各值距離軸線中心的距離來標示各值。在以下範例中,它們為紅色。
const config = {
type: 'radar',
data,
options: {
scales: {
r: {
ticks: {
color: 'red'
}
}
}
}
};
const labels = Utils.months({count: 7});
const data = {
labels: labels,
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgba(54, 162, 235, 0.5)',
borderColor: 'rgb(54, 162, 235)',
borderWidth: 1,
data: [10, 20, 30, 40, 50, 0, 5],
}]
};