Changing borderDash for specific gridLines in radar chart

1.3k Views Asked by At

I am using ChartJS to generate a radar chart.

I wish for the last gridLine (the outermost) to remain solid, while all the others are dashed.

Picture example:

adoreboard radar chart on imgur

I've seen that it is possible to have varying borderDash in this pull request which also shows an image of it in action but have yet to find a way to script it. (edit: it seems that the linked pull request has made it onto master, planned for release with V3.0 - meaning it is not yet available(?))

Quick example code of a script:

scale: {
gridLines: {
    borderDash: function(context) {
        return context.index % 2 === 0 ? [2, 3] : [10, 10];
    },
},
1

There are 1 best solutions below

0
On BEST ANSWER

You can already use Chart.js version 3, it's available as Chart.js 3.0.0-beta.

Simply add the following script tag to your HTML page.

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.0.0-beta/chart.min.js"></script>

Please take a look at the following code snippet and see how it works.

new Chart("radar-chart", {
  type: 'radar',
  data: {
    labels: ["A", "B", "C", "D", "E"],
    datasets: [{
      data: [25.48, 54.16, 7.61, 8.06, 4.45],
      backgroundColor: "rgba(255,99,132,0.2)",
      borderColor: "rgba(255,99,132,1)"
    }]
  },
  options: {
    legend: {
      display: false
    },
    scale: {
      ticks: {
        min: 0,
        max: 60,
        stepSize: 10
      },
      gridLines: {
        lineWidth: 2,
        color: "lightgreen",
        borderDash: context => context.index == 6 ? [] : [6, 4]
      }
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.0.0-beta/chart.min.js"></script>
<canvas id="radar-chart" height="120"></canvas>