需要帮助样式图 JS 雷达图
Need help styling chart JS Radar chart
我正在尝试为下面链接的雷达图设置背景样式,希望能够
- 设置雷达线的颜色
- 设置厚度
- 设置比例从 0-100
- 设置字体大小
我认为这必须通过 'options' 来完成(因为这与数据集无关)但是我对 JS 的掌握不够,在尝试了几个小时后无法让它工作。
Codepen here
Chart JS radar instructions here
new Chart(document.getElementById("radar-chart"), {
type: 'radar',
data: {
labels: ["Business", "Brand", "Marketing", "Stakeholders", "Clients"],
datasets: [
{
label: "",
fill: true,
backgroundColor: "rgba(255,99,132,0.2)",
borderColor: "rgba(255,99,132,1)",
pointBorderColor: "#fff",
pointBackgroundColor: "rgba(255,99,132,1)",
pointBorderColor: "#fff",
data: [25.48,54.16,7.61,8.06,4.45]
}
]
},
options: {
legend: {
display: false
},
borderWidth: 10,
}
});
为了得到你想要的,你可以定义ticks
, gridLines
and pointLabels
inside options.scale
.
new Chart(document.getElementById("radar-chart"), {
type: 'radar',
data: {
labels: ["Business", "Brand", "Marketing", "Stakeholders", "Clients"],
datasets: [{
data: [25.48, 54.16, 7.61, 8.06, 4.45],
fill: true,
backgroundColor: "rgba(255,99,132,0.2)",
borderColor: "rgba(255,99,132,1)",
pointBorderColor: "#fff",
pointBackgroundColor: "rgba(255,99,132,1)"
}]
},
options: {
legend: {
display: false
},
borderWidth: 10,
scale: {
ticks: {
fontSize: 18,
max: 100
},
gridLines: {
lineWidth: 2,
color: "lightgreen"
},
pointLabels: {
fontSize: 18,
fontStyle: "bold"
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.js"></script>
<canvas id="radar-chart" height="200"></canvas>
我正在尝试为下面链接的雷达图设置背景样式,希望能够
- 设置雷达线的颜色
- 设置厚度
- 设置比例从 0-100
- 设置字体大小
我认为这必须通过 'options' 来完成(因为这与数据集无关)但是我对 JS 的掌握不够,在尝试了几个小时后无法让它工作。
Codepen here Chart JS radar instructions here
new Chart(document.getElementById("radar-chart"), {
type: 'radar',
data: {
labels: ["Business", "Brand", "Marketing", "Stakeholders", "Clients"],
datasets: [
{
label: "",
fill: true,
backgroundColor: "rgba(255,99,132,0.2)",
borderColor: "rgba(255,99,132,1)",
pointBorderColor: "#fff",
pointBackgroundColor: "rgba(255,99,132,1)",
pointBorderColor: "#fff",
data: [25.48,54.16,7.61,8.06,4.45]
}
]
},
options: {
legend: {
display: false
},
borderWidth: 10,
}
});
为了得到你想要的,你可以定义ticks
, gridLines
and pointLabels
inside options.scale
.
new Chart(document.getElementById("radar-chart"), {
type: 'radar',
data: {
labels: ["Business", "Brand", "Marketing", "Stakeholders", "Clients"],
datasets: [{
data: [25.48, 54.16, 7.61, 8.06, 4.45],
fill: true,
backgroundColor: "rgba(255,99,132,0.2)",
borderColor: "rgba(255,99,132,1)",
pointBorderColor: "#fff",
pointBackgroundColor: "rgba(255,99,132,1)"
}]
},
options: {
legend: {
display: false
},
borderWidth: 10,
scale: {
ticks: {
fontSize: 18,
max: 100
},
gridLines: {
lineWidth: 2,
color: "lightgreen"
},
pointLabels: {
fontSize: 18,
fontStyle: "bold"
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.js"></script>
<canvas id="radar-chart" height="200"></canvas>