Getting Started

Before we start with the Chart, please refer this page for general information regarding integrating Syncfusion widget’s.

Adding script reference

To render the SunburstChart control, the following list of external dependencies are needed,

  • jQuery - 1.7.1 and later versions
  • Angular - angular latest versions

The required angular script as angular.min.js and ej.widget.angular.min.js which can be available in below CDN links:

The other required internal dependencies are tabulated below,

Files Description/Usage
ej.core.min.js It is referred always before using all the JS controls.
ej.data.min.js Used to handle data operation and is used while binding data to the JS controls.
ej.sunburstchart.min.js Sunburst Chart core script file which includes chart related scripts files.

NOTE

Refer the ej.web.all.min.js (which encapsulates all the ej controls and frameworks in a single file) in the application instead of referring all the above specified internal dependencies.

So the complete boilerplate code is

  • html
  • <!DOCTYPE html>
        <html xmlns="http://www.w3.org/1999/xhtml" lang="en" ng-app="syncApp">
        <head>
        <title>Essential Studio for AngularJS: Chart</title>
        <!-- Essential Studio for JavaScript  theme reference -->
        <link href="http://cdn.syncfusion.com/18.3.0.35/js/web/flat-azure/ej.web.all.min.css" rel="stylesheet" />
        <!-- Essential Studio for JavaScript  script references -->
        <script src="http://cdn.syncfusion.com/js/assets/external/jquery-3.0.0.min.js"></script>
        <script src="http://cdn.syncfusion.com/js/assets/external/jsrender.min.js"></script>
        <script src="http://cdn.syncfusion.com/js/assets/external/angular.min.js"></script>    
        <script src="http://cdn.syncfusion.com/18.3.0.35/js/web/ej.web.all.min.js"></script>
        <script src="http://cdn.syncfusion.com/18.3.0.35/js/common/ej.widget.angular.min.js" type="text/javascript"></script>
        <!-- Add your custom scripts here -->
        </head>
        <body>
        </body>
        </html>

    NOTE

    1. In production, we highly recommend you to use our custom script generator to create custom script file with required controls and its dependencies only. Also to reduce the file size further please use GZip compression in your server.
    2. For themes, you can use the ej.web.all.min.css CDN link from the code snippet given. To add the themes in your application, please refer to this link.

    Initialize Sunburst Chart

    1. Add a div element that acts as a container for e-ejsunburstchart.
  • html
  • <html>
    <body>
        <div id="chart"></div>
    </body>
    </html>

    Populate Data source:

    The datasource for the Sunburst Chart is populated as a JSON object. The “default_data” contains the JSON data for rendering the Sunburst Chart as shown in the sample.

  • js
  • var default_data = [
    
    { Category: "Employees", Country: "USA", JobDescription: "Sales", JobGroup: "Executive", EmployeesCount: 50 },
    { Category: "Employees", Country: "USA", JobDescription: "Sales", JobGroup: "Analyst", EmployeesCount: 40 },
    { Category: "Employees", Country: "USA", JobDescription: "Marketing", EmployeesCount: 40 },
    { Category: "Employees", Country: "USA", JobDescription: "Technical", JobGroup: "Testers", EmployeesCount: 55 },
    { Category: "Employees", Country: "USA", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Windows", EmployeesCount: 175 },
    { Category: "Employees", Country: "USA", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Web", EmployeesCount: 70 },
    { Category: "Employees", Country: "USA", JobDescription: "Management", EmployeesCount: 40 },
    { Category: "Employees", Country: "USA", JobDescription: "Accounts", EmployeesCount: 60 },
    
    { Category: "Employees", Country: "India", JobDescription: "Technical", JobGroup: "Testers", EmployeesCount: 43 },
    { Category: "Employees", Country: "India", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Windows", EmployeesCount: 125 },
    { Category: "Employees", Country: "India", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Web", EmployeesCount: 60 },
    { Category: "Employees", Country: "India", JobDescription: "HR Executives", EmployeesCount: 70 },
    { Category: "Employees", Country: "India", JobDescription: "Accounts", EmployeesCount: 45 },
    
    { Category: "Employees", Country: "Germany", JobDescription: "Sales", JobGroup: "Executive", EmployeesCount: 30 },
    { Category: "Employees", Country: "Germany", JobDescription: "Sales", JobGroup: "Analyst", EmployeesCount: 40 },
    { Category: "Employees", Country: "Germany", JobDescription: "Marketing", EmployeesCount: 50 },
    { Category: "Employees", Country: "Germany", JobDescription: "Technical", JobGroup: "Testers", EmployeesCount: 40 },
    { Category: "Employees", Country: "Germany", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Windows", EmployeesCount: 65 },
    { Category: "Employees", Country: "Germany", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Web", EmployeesCount: 27 },
    { Category: "Employees", Country: "Germany", JobDescription: "Management", EmployeesCount: 33 },
    { Category: "Employees", Country: "Germany", JobDescription: "Accounts", EmployeesCount: 55 },
    
    { Category: "Employees", Country: "UK", JobDescription: "Technical", JobGroup: "Testers", EmployeesCount: 45 },
    { Category: "Employees", Country: "UK", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Windows", EmployeesCount: 96 },
    { Category: "Employees", Country: "UK", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Web", EmployeesCount: 55 },
    { Category: "Employees", Country: "UK", JobDescription: "HR Executives", EmployeesCount: 60 },
    { Category: "Employees", Country: "UK", JobDescription: "Accounts", EmployeesCount: 30 },
    
    { Category: "Employees", Country: "France", JobDescription: "Technical", JobGroup: "Testers", EmployeesCount: 40 },
    { Category: "Employees", Country: "France", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Windows", EmployeesCount: 65 },
    { Category: "Employees", Country: "France", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Web", EmployeesCount: 27 },
    { Category: "Employees", Country: "France", JobDescription: "Marketing", EmployeesCount: 50 }
    
     ];

    Initialize Sunburst Chart with data

    Now, bind the default_Datasource to datasource property of the Sunburst Chart. Thelevelsproperty determines the number of hierarchical levels. Each hierarchy level is formed based on the property specified in groupMemberPath property, and each arc segment size is calculated using valueMemberPath.

    1. Add a script tag anywhere in the web page and add the following code.
  • js
  • <div id="container" ej-sunburstchart e-datasource="dataSource" e-valuememberpath="Population" e-levels= "levels">					
    </div>
           <script>
                //..
                angular.module('SunburstChartApp', ['ejangular'])
                .controller('SunburstChartCtrl', function ($scope) {
                $scope.dataSource = default_data;
                $scope.levels = [
    						{ groupMemberPath:"Country"},
    					  {groupMemberPath:"JobDescription"},
    						{ groupMemberPath:"JobGroup"},
    						{ groupMemberPath:"JobRole"}
    	];
                    });
            </script>
    
    </script>
    1. The final HTML file appears as follows
  • html
  • <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
            <title></title>
           <!--  jquery script  -->
            <script src="http://code.jquery.com/jquery-1.10.1.min.js" type="text/javascript"></script>
        
            <!-- Essential JS UI widget -->
            <script src="http://cdn.syncfusion.com/15.1.0.37/js/ej.widget.angular.min.js"></script>
           
            <!-- Essential JS theme -->
            <script src="http://cdn.syncfusion.com/15.1.0.37/js/web/flat-azure/ej.web.all.min.css" type="text/javascript"></script>
    
            <!-- SunburstData -->
            <script type="text/javascript">
    
                var default_data = [
    
    { Category: "Employees", Country: "USA", JobDescription: "Sales", JobGroup: "Executive", EmployeesCount: 50 },
    { Category: "Employees", Country: "USA", JobDescription: "Sales", JobGroup: "Analyst", EmployeesCount: 40 },
    { Category: "Employees", Country: "USA", JobDescription: "Marketing", EmployeesCount: 40 },
    { Category: "Employees", Country: "USA", JobDescription: "Technical", JobGroup: "Testers", EmployeesCount: 55 },
    { Category: "Employees", Country: "USA", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Windows", EmployeesCount: 175 },
    { Category: "Employees", Country: "USA", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Web", EmployeesCount: 70 },
    { Category: "Employees", Country: "USA", JobDescription: "Management", EmployeesCount: 40 },
    { Category: "Employees", Country: "USA", JobDescription: "Accounts", EmployeesCount: 60 },
    
    { Category: "Employees", Country: "India", JobDescription: "Technical", JobGroup: "Testers", EmployeesCount: 43 },
    { Category: "Employees", Country: "India", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Windows", EmployeesCount: 125 },
    { Category: "Employees", Country: "India", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Web", EmployeesCount: 60 },
    { Category: "Employees", Country: "India", JobDescription: "HR Executives", EmployeesCount: 70 },
    { Category: "Employees", Country: "India", JobDescription: "Accounts", EmployeesCount: 45 },
    
    { Category: "Employees", Country: "Germany", JobDescription: "Sales", JobGroup: "Executive", EmployeesCount: 30 },
    { Category: "Employees", Country: "Germany", JobDescription: "Sales", JobGroup: "Analyst", EmployeesCount: 40 },
    { Category: "Employees", Country: "Germany", JobDescription: "Marketing", EmployeesCount: 50 },
    { Category: "Employees", Country: "Germany", JobDescription: "Technical", JobGroup: "Testers", EmployeesCount: 40 },
    { Category: "Employees", Country: "Germany", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Windows", EmployeesCount: 65 },
    { Category: "Employees", Country: "Germany", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Web", EmployeesCount: 27 },
    { Category: "Employees", Country: "Germany", JobDescription: "Management", EmployeesCount: 33 },
    { Category: "Employees", Country: "Germany", JobDescription: "Accounts", EmployeesCount: 55 },
    
    { Category: "Employees", Country: "UK", JobDescription: "Technical", JobGroup: "Testers", EmployeesCount: 45 },
    { Category: "Employees", Country: "UK", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Windows", EmployeesCount: 96 },
    { Category: "Employees", Country: "UK", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Web", EmployeesCount: 55 },
    { Category: "Employees", Country: "UK", JobDescription: "HR Executives", EmployeesCount: 60 },
    { Category: "Employees", Country: "UK", JobDescription: "Accounts", EmployeesCount: 30 },
    
    { Category: "Employees", Country: "France", JobDescription: "Technical", JobGroup: "Testers", EmployeesCount: 40 },
    { Category: "Employees", Country: "France", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Windows", EmployeesCount: 65 },
    { Category: "Employees", Country: "France", JobDescription: "Technical", JobGroup: "Developers", JobRole: "Web", EmployeesCount: 27 },
    { Category: "Employees", Country: "France", JobDescription: "Marketing", EmployeesCount: 50 }
    
     ];
    
            </script>
          </head>
        <body>
        	  
          <div id="container" ej-sunburstchart e-datasource="dataSource"   
         e-valuememberpath="Population" e-levels= "levels">
    
        </div>
            <script>
                angular.module('SunburstChartApp', ['ejangular'])
                .controller('SunburstChartCtrl', function ($scope) {
                $scope.dataSource = default_data;
                $scope.levels = [
    						{ groupMemberPath:"Country"},
    						{groupMemberPath:"JobDescription"},
    						{ groupMemberPath:"JobGroup"},
    						{ groupMemberPath:"JobRole"}
               	];
                    });
            </script>      
        </body>
        </html>

    Add Title to the Sunburst Chart

    The title of the Sunburst chart is used to provide quick information to the user about the data being plotted in the Sunburst Chart. You can add it by using the text property of the e-title

  • js
  • <div id="container" ej-sunburstchart e-title-visible="true" e-title-text="Employee Count">					
    </div>

    Enable Legend

    You can enable or disable the legend by using the visible property present inside the e-legend

  • js
  • <div id="container" ej-sunburstchart e-legend-visible="true" >					
    </div>

    Add Data Labels

    The data labels are used to improve the readability of the Sunburst chart. This can be achieved by enabling the visible property in the e-datalabelsettings

  • js
  • <div id="container" ej-sunburstchart e-datalabelsettings-visible="true" >					
    </div>

    Now the Sunburst Chart is rendered along with the specified customizations

    Click here to view the default sample of the SunburstChart