Hide points in ChartJS LineGraph
Asked Answered
H

5

127

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.

Heelandtoe answered 28/1, 2016 at 22:55 Comment(0)
T
228

You 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.

Tremayne answered 8/11, 2016 at 5:50 Comment(2)
this config is global, but I got a chart which included 3 lines chart, I just wanna disable one of themDigestible
@Digestible you can set the pointRadius property on each individual dataset object. See @Alexander's answer below.Hexagon
A
144

You can set the pointRadius to zero.

var myChart = new Chart(
    ctx, {
        type: 'line',
        data: {
            labels: [...]
            datasets: [
              {
                data: [...],
                pointRadius: 0,  # <<< Here.
              }
            ]
        },
        options: {}
    })
Asa answered 1/3, 2018 at 13:22 Comment(4)
I've added "borderWidth: 1" and "pointRadius: 0.5" because I also needed a fine line and tiny dots to hover over them.Roseannroseanna
I needed to add pointHitRadius: 0 as well to disable tooltips.Pardner
@throrin19 What did not work? It is fully documented per the link above.Asa
Oups sorry. I think I have disabled my click. My problem was with vue-chartjs. Options have not sync correctly with chartJSObstruent
B
8

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)'
                }
            }
        }
    };
Blowpipe answered 23/2, 2022 at 15:51 Comment(0)
V
4

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
    }
});
Voluminous answered 2/8, 2023 at 2:20 Comment(1)
This is the best answer! The only problem is that TS doesn't like the pointstyle being a boolean, but I just suppress thatBondwoman
C
1

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

Confront answered 11/12, 2023 at 21:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.