[Chartjs]-How to remove some points in chartjs

4πŸ‘

βœ…

First, change pointRadius to array:

pointRadius: [8, 8, 8, 8, 8, 8, 8]

Then, you have to rewrite this array with specific values for each point (in our case, the second last pont) and update:

$("#btnRemovePoints").click(function()
{
    //change the radius of every point except one
    myChart.data.datasets[0].pointRadius = [0, 0, 0, 0, 0, 8, 0];
    myChart.update();
});

More details in this fiddle: https://jsfiddle.net/s7m1961t/

0πŸ‘

 $( document ).ready(function() {
      //My Chart 1
      myChart1.data.datasets[0].pointRadius = [0, 0, 0, 0, 0, 8, 0];
        myChart1.update();
      //My Chart 2
      myChart2.data.datasets[0].pointRadius = [0, 0, 0, 0, 0, 8, 0];
        myChart2.update();         
    });

0πŸ‘

works on version 4.2.1
The code displays events as dots if the checkbox is pressed, otherwise, the graph is without dots.

labels – dates. datasets – the number of vacancies

const v = checkbox.value // getting the value from the checkbox
// where there are no events, we put 0, and where there are 10. 
// that is, we make either visible or invisible points
const points = labels.map(date => (date.events ? 10 : 0)) 
// if the checkbox is pressed, then we show points, otherwise we do not show any points
chart.data.datasets[0].pointRadius = v ? points : [] 
chart.update()

Leave a comment