Open In App

Chart.js Polar Area Chart

Chart.js Polar Area Chart is the type of chart that represents the data in a circular shape format which is quite similar to the pie chart. Like the pie chart, each segment in the Polar Area chart has the same angle with the radius of the segment different from each other. This Polar Area chart is mainly used to provide a visual representation of comparative data.

Dataset Properties

Config Options

Syntax

new Chart($("#ID"), {
   type: 'polarArea',
   data: {
      labels: ["Label 1", "Label 2", "Label 3", /* ... */],
      datasets: [{
         data: [value1, value2, value3, /* ... */], 
         backgroundColor: ["Color 1", "Color 2", "Color 3", /* ... */], 
         // Additional dataset options if needed
      }]
   },
   options: { ...
   }
});

CDN link

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.0.1/dist/chart.umd.min.js"></script>

Example 1: The example below shows a simple representation of a Polar Area Chart using Chart.js. The chart mainly represents the usage percentage of programming language on GeeksforGeeks.






<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
                                   initial-scale=1.0">
    <title>GeeksforGeeks Polar Area Chart</title>
    <script src=
    </script>
    <script src=
    </script>
</head>
 
<body>
    <div>
        <h1 style="color:green;">
            GeeksforGeeks
        </h1>
        <h3>
            Chart JS Polar Area Chart Example 1
        </h3>
        <div><canvas id="programmingChart"
                     width="400" height="400">
             </canvas>
        </div>
    </div>
    <script>
        new Chart($("#programmingChart"), {
            type: 'polarArea',
            data: {
                labels: ["Java", "Python", "C++",
                         "JavaScript", "C#"],
                datasets: [{
                    data: [25, 30, 15, 20, 10],
                    backgroundColor: ["#FF6384",
                            "#36A2EB", "#FFCE56",
                            "#4CAF50", "#9C27B0"],
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                title: {
                    display: true,
                    text: 'Programming Language Usage on GeeksforGeeks'
                }
            }
        });
    </script>
</body>
 
</html>

Output:

Example 2: In the below example, we have used different attributes to styles. We are representing the content distribution in categories like articles, courses, visitors, etc.






<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
                                   initial-scale=1.0">
    <title>GeeksforGeeks Polar Area Chart</title>
    <script src=
    </script>
    <script src=
    </script>
</head>
 
<body>
    <div>
        <h1 style="color:green;">
            GeeksforGeeks
        </h1>
        <h3>
            Chart JS Polar Area Chart Example 2
        </h3>
        <div><canvas id="geeksChart"
                     width="400" height="400">
        </canvas></div>
    </div>
    <script>
        const data = {
            labels: ["Programming", "Articles",
                     "Courses", "Visitors"],
            datasets: [{
                data: [30, 40, 20, 10],
                backgroundColor: ["#FF6384", "#36A2EB",
                                  "#FFCE56", "#4CAF50"],
                hoverBackgroundColor: ["#FF6384", "#36A2EB",
                                       "#FFCE56", "#4CAF50"],
                hoverBorderColor: "#fff",
                hoverBorderWidth: 2,
                circular: false,
            }]
        };
        const config = {
            type: 'polarArea',
            data: data,
            options: {
                responsive: true,
                maintainAspectRatio: false,
                title: {
                    display: true,
                    text: 'GeeksforGeeks Polar Area Chart'
                },
                animation: {
                    animateRotate: true,
                    animateScale: true
                }
            }
        };
        new Chart($("#geeksChart"), config);
    </script>
</body>
 
</html>

Output:


Article Tags :