admin 管理员组文章数量: 1086019
I want to change the size of a specific point on a line chart in Chart.js. I saw in this answer how to change the color of a point but I can't find a solution for changing its size. Any ideas?
// dataArray and labelsArray are hard-coded arrays of int values.
var lineChartData = {
datasets: [{
data: dataArray,
pointStrokeColor: "#fff",
fillColor: "rgba(220,220,220,0.5)",
pointColor: "rgba(220,220,220,1)",
strokeColor: "rgba(220,220,220,1)"
}],
labels: labelsArray
};
// Changing color of point #5
myLineChart.datasets[0].points[4].fillColor = "#FF0000";
// Changing point's size
// TODO:
I want to change the size of a specific point on a line chart in Chart.js. I saw in this answer how to change the color of a point but I can't find a solution for changing its size. Any ideas?
// dataArray and labelsArray are hard-coded arrays of int values.
var lineChartData = {
datasets: [{
data: dataArray,
pointStrokeColor: "#fff",
fillColor: "rgba(220,220,220,0.5)",
pointColor: "rgba(220,220,220,1)",
strokeColor: "rgba(220,220,220,1)"
}],
labels: labelsArray
};
// Changing color of point #5
myLineChart.datasets[0].points[4].fillColor = "#FF0000";
// Changing point's size
// TODO:
Share
Improve this question
edited May 23, 2017 at 12:25
CommunityBot
11 silver badge
asked May 3, 2016 at 8:36
YulianYulian
6,78911 gold badges71 silver badges103 bronze badges
7
- show your plete code of linechart – Akhilesh Singh Commented May 3, 2016 at 8:38
- Maybe this answer can help you: stackoverflow./questions/31522001/… – Jeroen Bellemans Commented May 3, 2016 at 8:43
- @JeroenBellemans - I can't find anything useful there. Could you be more specific please? – Yulian Commented May 3, 2016 at 8:47
- @AkhileshSingh - I updated my question. – Yulian Commented May 3, 2016 at 8:47
- Wasn't there an accepted answer with the options to increase the size of the dots & labels? – Jeroen Bellemans Commented May 3, 2016 at 8:51
2 Answers
Reset to default 5Late Answer. But it'll be helpful for the people who is searching for this.
Code to set different point size in line chart in Chart.js.
var speedCanvas = document.getElementById("speedChart");
var pointRadius=[];
var dataFirst = {
label: "Car A - Speed (mph)",
data: [10, 59, 75, 25, 20, 65, 40],
lineTension: 0.3,
fill: false,
borderColor: 'red',
backgroundColor: 'transparent',
pointBackgroundColor: 'green',
pointBorderColor:'green',
pointRadius: pointRadius
};
var speedData = {
labels: ["0s", "10s", "20s", "30s", "40s", "50s", "60s"],
datasets: [dataFirst]
};
var chartOptions = {
legend: {
display: true,
position: 'top',
labels: {
boxWidth: 80,
fontColor: 'black'
}
}
};
var lineChart = new Chart(speedCanvas, {
type: 'line',
data: speedData,
options: chartOptions
});
for(var i=0;i<this.lineChart.data.datasets[0].data.length;i++){
pointRadius.push(i);
}
lineChart.update();
The below code is to set the point size.
for(var i=0;i<this.lineChart.data.datasets[0].data.length;i++){
pointRadius.push(i);
}
lineChart.update();
This method is working in latest versions of ChartJS
Running CodePen Example : CodePen Example
You can Simply increase the size of dot in line chart follow the Documentation of Chart.js. There is customizing method is available.
You can try this:
var myLineChart = Chart.Line(ctx, {
pointDot: false,
pointLabelFontSize: 20
});
lineChartData = {
datasets: [{
data: dataArray,
pointStrokeColor: "#fff",
fillColor: "rgba(220,220,220,0.5)",
pointColor: "rgba(220,220,220,1)",
strokeColor: "rgba(220,220,220,1)"
}],
labels: labelsArray
};
// Changing color of point #5
myLineChart.datasets[0].points[4].fillColor = "#FF0000";
pointLabelFontSize: 20 // Font Size in pixel
Refrence1
Linechart
本文标签: javascriptChange size of a specific point on a line chart in ChartjsStack Overflow
版权声明:本文标题:javascript - Change size of a specific point on a line chart in Chart.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744019597a2519563.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论