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