Getting Started

6 Jun 202311 minutes to read

This section explains you the steps required to populate the Sunburst Chart with data, data labels, legend and title. This section covers only the minimal features that you need to know to get started with the Sunburst Chart.

Adding Script Reference

Create an HTML page and add the scripts references in the order mentioned in the following code example.

  • jQuery 1.10.2 and later versions

The required ReactJS script dependencies as follows. And you can also refer React to know more about react js.

To get started, you can use the ej.web.all.min.js file that encapsulates all the ej controls and frameworks in one single file.

  • HTML
  • <!DOCTYPE html>
       <html>
         <head>
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <meta name="description" content="Essential Studio for React JS">
            <meta name="author" content="Syncfusion">
            <title>Getting Started for Ribbon React JS</title>
            <!-- Essential Studio for JavaScript  theme reference -->
            <link href="http://cdn.syncfusion.com/24.2.3/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/react.min.js"></script>
            <script src="http://cdn.syncfusion.com/js/assets/external/react-dom.min.js"></script>
            <script src="http://cdn.syncfusion.com/24.2.3/js/web/ej.web.all.min.js"></script>
            <script src="http://cdn.syncfusion.com/24.2.3/js/common/ej.web.react.min.js"></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.

    Control Initialization

    Control can be initialized in two ways.

    • Using jsx Template
    • Without using jsx Template

    Using jsx Template

    By using the jsx template, we can create the html file and jsx file. The .jsx file can be convert to .js file and it can be referred in html page.

    Create Sunburst Chart

    You can easily create the Sunburst Chart widget by following the below steps.

    1.Create a <div> tag.

  • HTML
  • <!DOCTYPE html>
        <html> 
            <body> 
                <div id="sunburst"></div>
                    <script src="app/sunburstchart/default.js">
                    </script>
            </body>
        </html>

    2.Initialize the Sunburst chart by using the EJ.SunburstChart tag

  • JAVASCRIPT
  • "use strict";
     ReactDOM.render(
        <EJ.SunburstChart id = "sunburst1">                  
        </EJ.SunburstChart>,
              document.getElementById('sunburst')
    );

    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. Thelevels property 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.

  • JS
  • "use strict"; 
     var levels=[
            {groupMemberPath: "Country" },
            {groupMemberPath: "JobDescription"},
            {groupMemberPath: "JobGroup"},
            {groupMemberPath: "JobRole" }
        ];
        
     ReactDOM.render(
        <EJ.SunburstChart id = "sunburst1" valueMemberPath = "EmployeesCount"  
        dataSource = {default_data}    
        levels = {levels} ></EJ.SunburstChart>,
              document.getElementById('sunburst')
    );

    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 title

  • JS
  • "use strict";
     var title = { text:'Employees Count'};
     ReactDOM.render(
        <EJ.SunburstChart id = "sunburst1"
         title = {title}></EJ.SunburstChart>,
              document.getElementById('sunburst')
    );

    Enable Legend

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

  • JS
  • "use strict";
     var legend = { visible:true, position: "left" }; 
     ReactDOM.render(
        <EJ.SunburstChart id = "sunburst1"     
        legend = {legend}></EJ.SunburstChart>,
              document.getElementById('sunburst')
    );

    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 datalabelSettings.

  • JS
  • "use strict";
    var datalabelSettings = { visible:true};
    ReactDOM.render(
        <EJ.SunburstChart id = "sunburst1"     
         datalabelSettings = {datalabelSettings}></EJ.SunburstChart>,
              document.getElementById('sunburst')
    );

    Now the Sunburst Chart is rendered along with the specified customizations

    Click here to view the default sample of the SunburstChart