Displaying data metrics with Radar Charts in chart.js to illustrate point values

Is there a way to display the values on the chart using chart.js?

UPDATE: I've tried using the options provided below but haven't been able to find a solution.

    options: {
    scale: {
      angleLines: {
        lineWidth: 0.5,
        color: 'rgba(128, 128, 128, 0.2)'
      },
      pointLabels: {
        fontSize: 14,
        fontStyle: '300',
        fontColor: 'rgba(204, 204, 204, 1)',
        fontFamily: "'Lato', sans-serif"
      },
      ticks: {
        beginAtZero: true,
        maxTicksLimit: 4,
        min: 0,
        max: 4,
        display: false
      }
    }
}



Check out this sample pen for reference: https://codepen.io/melvik/pen/ZEGaexy

expected result https://i.sstatic.net/cfZpr.png

Thank you in advance

Answer №1

chartjs-plugin-datalabels & chart.js radar.

datalabels Datalabels Formatter

1/2. Simple example - displaying "hello world"

https://i.sstatic.net/A6zRO.png

2/2. "real-life example" - display value:

formatter: function(value, context) {
  return context.chart.data.labels[context.value];
}

https://i.sstatic.net/NaFYw.png

tooltip: false

Disable tooltip (Use a visible value instead)

tooltips: false,

Basic code snippet:

// Modify default options for ALL charts
Chart.helpers.merge(Chart.defaults.global.plugins.datalabels, {
  opacity: 1,
  textAlign: 'left',
  color: 'white',
  borderColor: '#11469e',
  borderWidth: 2,
  borderRadius: 100,
  font: {
    weight: 'bold',
    size: 12,
    lineHeight: 1 /* center align */
  },
  padding: {
    top: 5
  },
  /* hover effect */
  backgroundColor: function(context) {
    return context.hovered ? context.dataset.borderColor : 'white';
  },
  color: function(context) {
    return context.hovered ? 'white' : context.dataset.borderColor;
  },
  listeners: {
    enter: function(context) {
      context.hovered = true;
      return true;
    },
    leave: function(context) {
      context.hovered = false;
      return true;
    }
  }
});

var data = {
  labels: ["Ball Skills", "Shooting", "Physical", "Defence", "Passing"],
  datasets: [{
    label: "De maria",
    backgroundColor: "rgba(38,120,255,0.2)",
    borderColor: "rgba(38,120,255, 1)",
    data: [90, 86, 76, 65, 82]
  }]
};

var options = {
  responsive: true,
  tooltips: false,
  title: {
    text: 'chartjs-plugin-datalabels - basic example',
    display: true,
    position: `bottom`,
  },
  plugins: {
    /* ######### https://chartjs-plugin-datalabels.netlify.com/ #########*/
    datalabels: {
      /* formatter */
      formatter: function(value, context) {
        return context.chart.data.labels[context.value];
      }
    }
  },
  /* scale: https://www.chartjs.org/docs/latest/axes/radial/linear.html#axis-range-settings */
  scale: {
    angleLines: {
      display: true
    },
    pointLabels:{
      /* https://www.chartjs.org/docs/latest/axes/radial/linear.html#point-label-options */
      fontSize: 15,
      fontColor: 'black',
      fontStyle: 'bold',
      callback: function(value, index, values) {
        return value;
      }
    },
    ticks: {
      /* https://www.chartjs.org/docs/latest/axes/styling.html#tick-configuration */
      /* suggestedMax and suggestedMin settings only change the data values that are used to scale the axis */
      suggestedMin: 0,
      suggestedMax: 100,
      stepSize: 25, /* 25 - 50 - 75 - 100 */
      maxTicksLimit: 11, /* Or use maximum number of ticks and gridlines to show */
      display: false, // remove label text only,
    }
  },
  legend: {
    labels: {
      padding: 10,
      fontSize: 14,
      lineHeight: 30,
    },
  },
};

var myChart = new Chart(document.getElementById("chart"), {
  type: 'radar',
  data: data,
  options: options
});
<canvas id="chart" width="500" height="350"></canvas>
<br>
<br>
<a href="https://chartjs-plugin-datalabels.netlify.com/" target="_blank">chartjs-plugin-datalabels</a>


<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d1b2b9b0a3a5ffbba291e3ffe9ffe1">[email protected]</a>"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4a7aca5b6b0aeb7e9b4a8b1a3adaae9a0a5b0a5a8a5a6a1a8b784f4eaf3eaf4">[email protected]</a>/dist/chartjs-plugin-datalabels.min.js"></script>

codepen: https://codepen.io/ezra_siton/pen/bGdYaLd

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the method for substituting one text with another using two-way data binding?

I implemented two different cases in my Mat-Table. When there is no data, the user will see a message saying "No Data Found". However, if the user enters text in the filter search, the "No Data Found" message should be hidden and replaced with the entered ...

`Gradient blending in ChartJS`

Currently, I am facing an issue with my line chart having 2 datasets filled with gradients that overlap, causing a significant color change in the 'bottom' dataset. Check out my Codepen for reference: https://codepen.io/SimeriaIonut/pen/ydjdLz ...

Having trouble displaying form in a different view, form is not appearing as expected

I am facing an issue with rendering a form inside a modal. The form is being rendered but the form_for does not show up, only the inputs are visible. This prevents me from targeting the submit button, which I need for ajax functionality. My file path: Adg ...

Exploring the Document Object Model to locate the adjacent sibling of a parent element

If I need to implement an event that hides the section .dependent-box whenever the element with class .radio-click-hide is clicked, what would be the best approach for traversing the elements to achieve this functionality? I have attempted the following co ...

Tips for selecting checkboxes with fetched information

I have created a script that passes json data to a variable and then collects all the necessary information such as chapterid, questionid ...etc on the inner html page. jQuery Code: $('div[id^="questionsNo_"]').ready(function() { var assessme ...

The Angular scope fails to reflect changes on the view

In this angular ng-click event, I have the following code: eventApp.controller('DetailEventController', ['$scope', '$http', '$compile', '$timeout', function ($scope, $http, $compile, $timeout, uiCalendarCon ...

Determine if two arrays have the same object values

I have a situation where I am working with two arrays of objects. arr1 = [{ name: "John" }, { name: "Frank" }]; arr2 = [ { name: "John", age: 35 }, { name: "Frank", age: 22 }, { name: "Kate", age: 23 ...

Adjusting the height of one element based on the height of another element in multiple cases using jQuery

I am currently using jQuery to retrieve the height of one div and apply that value as a CSS property to another. Let's take a look at a sample layout: <div class="row"> <div class="column image"> <img src="image.jpg" /> < ...

Having difficulty invoking a JavaScript function through PHP

My goal is to achieve the following: <html> <script type="text/javascript" src="jquery.js"></script> <a id="random">before</a> <script> function test(a) { document.getElementById('random').innerHTM ...

Having trouble changing the style property of the `<div>` element in my JS function within Bootstrap Studio

I am currently utilizing Bootstrap in Bootstrap Studio along with plain JavaScript. One of the challenges I am facing pertains to changing the background color of a <div> element upon selecting a new tab. The objective is to dynamically alter the ba ...

Discovering the method to retrieve the value of an array in JavaScript

Currently, I am developing an Android application in Titanium Studio with a Rest API (Apigee Baas) as the backend. The data stored in the Apigee Baas includes fields such as name, address, and attendance records. When retrieving the response from the Rest ...

Animating elements on a webpage can be achieved by using both

Is there a way to create an animation that moves objects based on button clicks? For example, when the "Monday" button is pressed, the object with the correct color will move down. If any other button like "Tuesday" is clicked, the previous object will mov ...

How to load images in TreePanel in Ext JS

While creating an Ext.TreePanel, I wanted to include an image in the node along with the text containing the URL to the image. However, I encountered an issue where the image was not loading on the page, only the text was visible. Is there a way to display ...

Limit the bootstrap datepicker to display only certain dates and today's date

I've integrated the Bootstrap Datepicker into my website. I need to customize it so that only specific dates are enabled, including today's date, and all other years, months, and days are hidden from the Datepicker. How can I achieve this? Furth ...

AngularJS is receiving an array of null inputs

I have a form where data from my DB is displayed through WebApi. One of the controls will contain an array of values. There is a scenario where the user can edit and save it using the PUT function. Controller : $scope.Put= function () { $scope.i ...

What is the best way to access a computed property within the mounted or created hooks?

Is this the correct code for my situation? computed: { posts() { return this.$store.getters['posts/postsByUser'] }, loggedIn() { return this.$store.getters['auth/check']; }, user() { retu ...

In Vue, reactivity does not extend to nested child objects

I am dealing with JSON data structured like this- items: { id: 1, children: [{ id: 2, parentId: 1, children: [{ id: 3, parentId: 2 }] }] } level-1 children represent parent items that all possess a parent_id of 1 (the roo ...

Why won't the Laravel Livewire click function work after the PJAX container refresh?

I am currently using the pjax library in my application, and I recently integrated Livewire. However, I am facing difficulties in making them work together. Specifically, my issue is as follows: In my application, I have a grid displaying products with an ...

What is the method for retrieving hotels from a database based on their proximity to a specific set of latitude and longitude coordinates?

I have a database table with latitude, longitude, and hotel locations. I want to create a feature that will show hotels near a specific point defined by latitude and longitude. Code Snippet function findNearbyHotels() { $this->lo ...

Containers shared among Next.js pages within a folder

Is it possible to have a shared container for all pages within a specific folder in NextJS? One potential solution could involve the following code: // pages/folder/index.js export default function Container({ children }) { return <Container>{ch ...