Search results

Add legend in table with x-axis labels

23 Mar 2023 / 3 minutes to read

The annotation property is used to add legend in table and the multiLevelLabels property is used to customize the axis label in table format.

To add legend in table with x-axis labels, follow the given steps:

Step 1:

Initialize the custom elements using the annotation property.

Create table and rectangle shapes in the html page and set this to the content property of annotation.

By setting coordinateUnits value to pixel in annotation object, you can place the legend in chart based on pixel values.

Source
Preview
index.js
index.html
Copied to clipboard
Copied to clipboard
<!DOCTYPE html><html lang="en"><head>
            
    <title>EJ2 Animation</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/21.1.35/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element"></div>
    </div>
        <script id="templateWrap" type="text/x-template">
            <div style='width:80px; padding: 5px;'>
                                  <table style='width: 100%'>
                                      <tr> 
                                          <td><div id='first' style='width: 10px; height: 10px; background:skyblue;'></div></td>
                                          <td style='padding-left: 5px;'>Awarded</td>
                                      </tr>
                                      <tr>
                                          <td><div id='second' style='width: 10px; height: 10px; background:#b22222;'></div></td>
                                          <td style='padding-left: 5px;'>Paid</td>
                                      </tr>
                                  </table>
                              </div>
      </script>
      <script id="templateWrap1" type="text/x-template">
            <div style='width:80px; padding: 5px;'>
                                  <table style='width: 100%'>
                                      <tr> 
                                          <td><div style='border-style: solid;border-width: 1px; height:28px;width:85px; border-color: #b5b5b5;'></div></td>
                                      </tr>
                                
                                  </table>
                              </div>
      </script>
       <script id="templateWrap2" type="text/x-template">
            <div style='width:80px; padding: 5px;'>
                                  <table style='width: 100%'>
                                      <tr> 
                                          <td><div style='border-style: solid;border-width: 1px; height:28px;width:85px; border-color: #b5b5b5;'></div></td>
                                      </tr>
                                
                                  </table>
                              </div>
      </script>
  


<script>
var ele = document.getElementById('container');
if(ele) {
    ele.style.visibility = "visible";
 }   
        </script>
<script src="index.js" type="text/javascript"></script>
</body></html>