admin管理员组文章数量:1134247
Originally I set the fill color for each point to be completely transparent. If I run my mouse over the graph, the points pop up. I want to hide all points so that the line graph is smooth.
Originally I set the fill color for each point to be completely transparent. If I run my mouse over the graph, the points pop up. I want to hide all points so that the line graph is smooth.
Share Improve this question asked Jan 28, 2016 at 22:55 DanDan 1,9323 gold badges13 silver badges28 bronze badges5 Answers
Reset to default 231You can achieve this by setting point's radius property in configuration options as follows:
var chartConfig = {
type: 'line',
options: {
elements: {
point:{
radius: 0
}
}
}
}
Tooltips for the points will also gone off.
You can set the pointRadius
to zero.
var myChart = new Chart(
ctx, {
type: 'line',
data: {
labels: [...]
datasets: [
{
data: [...],
pointRadius: 0, # <<< Here.
}
]
},
options: {}
})
I had the same problem, but I wanted to keep the hover option active. There is my solution:
const config = {
type: 'line',
data: {
datasets:[{
label: 'Température',
borderColor: 'rgb(255, 99, 132)',
data: tempE,
pointStyle: 'rect',
}]
},
options: {
elements:{
point:{
borderWidth: 0,
radius: 10,
backgroundColor: 'rgba(0,0,0,0)'
}
}
}
};
What actually worked for me to remove the points and keep the tooltip with the version 4 was to set the pointStyle property to false. Is the last option in the list provided in the official docs.
The code could be something like this:
const chart = new Chart('canvas-id', {
type: 'line',
data: {
label: 'Some label',
data: [...],
pointStyle: false
}
});
You can set the radius: 0
to hide the dot, additionally you can turn up the hitRadius: 10
which sets the radius outside of the dot which you can hover to make the popover show. This allows you to hide the dot while still making the point easy to hover and open the tooltip.
var chartConfig = {
type: 'line',
options: {
elements: {
point: {
radius: 0,
hitRadius: 10,
}
}
}
}
More documentation on elements
in chart.js can be found here: https://www.chartjs.org/docs/latest/configuration/elements.html
本文标签: javascriptHide points in ChartJS LineGraphStack Overflow
版权声明:本文标题:javascript - Hide points in ChartJS LineGraph - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736787683a1952944.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论