How to summarize the circular call-out display data in the Hierarchical level ejTreeMap?
To summarize the circular call-out display data in the Hierarchical level ejTreeMap, follow the steps given.
Step 1:
Create a TreeMap sample and include the necessary script files.
Step 2:
Include the sales_data to the HTML script tag in order to populate the TreeMap control.
JS
<script> var sales_data = [ { Country: "United States", Name: "New York", Sales: 2353, Expense: 2000 }, { Country: "United States", Name: "Los Angeles", Sales: 3453, Expense: 3000 }, { Country: "United States", Name: "San Francisco", Sales: 8456, Expense: 8000 }, { Country: "United States", Name: "Chicago", Sales: 6785, Expense: 7000 }, { Country: "United States", Name: "Miami", Sales: 7045, Expense: 6000 }, { Country: "Canada", Name: "Toronto", Sales: 7045, Expense: 7000 }, { Country: "Canada", Name: "Vancouver", Sales: 4352, Expense: 4000 }, { Country: "Canada", Name: "Winnipeg", Sales: 7843, Expense: 7500 }, { Country: "Mexico", Name: "Mexico City", Sales: 7843, Expense: 6500 }, { Country: "Mexico", Name: "Cancun", Sales: 6683, Expense: 6000 }, { Country: "Mexico", Name: "Acapulco", Sales: 2454, Expense: 2000 } ] </script>
Step 3:
Summarize the circular call-out display data values by using the helper function and then the data that needs to be summarized can be passed to the path accessing it.
Provide values for Sales and Expenses, summarizing through the helper method called, ~addition, as given in the following code example.
JS
<script id="labeltemplate" type="application/jsrender"> <div align="center" style="width:120px; height:120px;background-image:url('images/circle.png');"> <table style="text-align:center;margin-left:-10px; margin-top:10px;" > <div style="margin-top:16px;margin-left:0px;"> <label style="color:white;font-size:16px;font-weight:normal;" id="Label2">Sales</label> </div> <div style="margin-top:-5px;"> <label style="color:white;font-size:15px;font-weight:normal;" id="Label5">{{:~addition(data,"Sales")}}</label> </div> <div style="margin-top:8px;margin-left:2px;"> <label style="color:white;font-size:16px;margin-top:-5px;font-weight:normal;" id="Label3">Expense</label> </div> <div style="margin-top:-5px;"> <label style="color:white;font-size:15px;font-weight:normal;" id="Label4">{{:~addition(data,"Sales")}}</label> </div> </table> </div> </script>
Helper function summarizes the data values of Sales and Expense as follows:
JS
$.views.helpers({ addition: function (data,property) { var sum=0; for(var index=0;index<data.length;index++) { sum += parseFloat(data[index][property]); } return sum; } });
JS
<script type="text/javascript"> jQuery(function ($) { $("#container").ejTreeMap({ dataSource: sales_data, . . . levels: [ { groupPath:"Country", groupGap:3, showHeader:true,headerHeight:25, showLabels: true, labelTemplate: 'labeltemplate' } ] . . . }); }); $.views.helpers({ addition: function (data,property) { var sum=0; for(var index=0;index<data.length;index++) { sum += parseFloat(data[index][property]); } return sum; } }); </script> . . . <script id="labeltemplate" type="application/jsrender"> <div align="center" style="width:120px; height:120px;background-image:url('images/circle.png');"> <table style="text-align:center;margin-left:-10px; margin-top:10px;" > <div style="margin-top:16px;margin-left:0px;"> <label style="color:white;font-size:16px;font-weight:normal;" id="Label2">Sales</label> </div> <div style="margin-top:-5px;"> <label style="color:white;font-size:15px;font-weight:normal;" id="Label5">{{:~addition(data,"Sales")}}</label> </div> <div style="margin-top:8px;margin-left:2px;"> <label style="color:white;font-size:16px;margin-top:-5px;font-weight:normal;" id="Label3">Expense</label> </div> <div style="margin-top:-5px;"> <label style="color:white;font-size:15px;font-weight:normal;" id="Label4">{{:~addition(data,"Sales")}}</label> </div> </table> </div> </script>
The following screenshot displays the summarized circular call-out display data values:
Sample Link:
https://www.syncfusion.com/downloads/support/directtrac/general/Hierarchical_TreeMap-29573981.zip