[Chartjs]-Chart.js color change of the data points

3๐Ÿ‘

โœ…

You can set point and point border to same color.

datasets: [
    {
      label: 'Dataset 1',
      data: Utils.numbers(NUMBER_CFG),
      fill: false,
      borderColor: Utils.CHART_COLORS.red,
      backgroundColor: '#1F363D', # Here
      borderWidth: 1,
      pointRadius: 5,
      pointBorderColor: '#1F363D' #Here
    },

enter image description here

1๐Ÿ‘

You can set the color value for each data point an array.

data: {
        labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 5, 2, 3],
            backgroundColor: [
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)'
            ],
            borderColor: [
                'rgba(255, 99, 132, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(54, 162, 235, 1)',
            ],
            borderWidth: 1
        }]

enter image description here

codepen โ€“ https://codepen.io/non_tech_guy/pen/VwzwRrL

The only catch I can see is the first borderColor value controls the color of the line but it is a step closer.

Leave a comment