English 中文(简体)
Chart.js - Mixed Chart
  • 时间:2024-12-22

Chart.js - Mixed Chart


Previous Page Next Page  

Chart.js also provides us a facipty to create charts having combination of two or different chart types. Such charts are called mixed charts. One of the most common examples of chart.js mixed chart is a bar chart including a pne dataset.

Syntax

The syntax for creating a mixed chart is given below −


type:  scatter ,
datasets: [
   { type:  scatter , data: value, },
   { type:  bar , data: value, },
]

Example

Let’s take an example with the help of which we will create a mixed chart −


<!DOCTYPE>
<html>
<head>
   <meta charset- "UTF-8" />
   <meta name="viewport" content="width=device-width, initial-scale=1" />
   <title>chart.js</title>
</head>
<body>
   <canvas id="chartId" aria-label="chart" height="300" width="580"></canvas>
   <script src="https://cdnjs.cloudflare.com/ajax/pbs/Chart.js/3.1.1/chart.min.js"></script>
   <script>
      var chrt = document.getElementById("chartId").getContext("2d");
      var chartId = new Chart(chrt, {
         type:  scatter ,
         data: {
            labels: ["HTML", "CSS", "JAVASCRIPT", "CHART.JS", "JQUERY", "BOOTSTRP"],
            datasets: [{
                  type:  scatter ,
                  label: "onpne tutorial subjects",
                  data: [
                     {x:10, y:14},
                     {x:25, y:35},
                     {x:21, y:20},
                     {x:35, y:28},
                     {x:15, y:10},
                     {x:19, y:30}
                  ],
                  backgroundColor: [ yellow ,  aqua ,  pink ,  pghtgreen ,  gold ,  pghtblue ],
                  borderColor: [ black ],
                  radius: 8,
               },
               {
                  type:  polarArea ,
                  label: "onpne tutorial exam",
                  data: [20, 40, 30, 35, 30, 20],
                  backgroundColor: [ navy ,  aqua ,  pink ,  pghtgreen ,  pghtblue ,  gold ],
                  borderColor: [ black ],
                  borderWidth: 2,
                  pointRadius: 5,
               }
            ],
         },
         options: {
            responsive: false,
            scales: {
               y: {
                  beginAtZero: true
               }
            }
         },
      });
   </script>
</body>
</html>

Output

Mixed Chart Advertisements