Grouping and Sorting

It's possible to group chart data by a certain property. You may use group method or group property in a chart constructor.


</> Source
<!DOCTYPE html>
<html>
<head>
	<title>Grouping and Sorting</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/fonts/font_roboto/roboto.css"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
	<script src="../../../codebase/dhtmlx.js"></script>
	<script src="../common/companies.js"></script>
	<script>
		var myBarChart;
		function doOnLoad() {
			myBarChart = new dhtmlXChart({
				view:"bar",
				container:"chart_container",
				value:"#sales#",
				preset:"alpha",
				label:"#id#",
				padding:{
					bottom:0
				},
				sort:{
					by:"#id#",
					as:"string",
					dir:"asc"
				},
				group:{
					by:"#year#",
					map:{
						sales:["#sales#","sum"]
					}
				}
			});
			myBarChart.parse(data,"json");
		}
		function  groupCompany(){
			myBarChart.group({
				by:"#company#",
				map:{
					sales:["#sales#","sum"]
				}
			});
			myBarChart.refresh();
		}
		function  groupSum(){
			myBarChart.group({
				by:"#year#",
				map:{
					sales:["#sales#","sum"]
				}
			});
		}
		function  groupMax(){
			myBarChart.group({
				by:"#year#",
				map:{
					sales:["#sales#","max"]
				}
			});
		}
	</script>
</head>
<body onload="doOnLoad();">
	<p>It's possible to group chart data by a certain property. You may use group method or group property in a chart constructor.</p>
	<div id="chart_container" style="width:600px;height:200px;border:1px solid #c0c0c0;"></div><br/>
	<input type="button" name="some_name" value="Group by" onclick="window['group'+document.getElementById('groupby').value]()">
	<select name="groupby" id="groupby">
		<option value="Company">company</option>
		<option value="Sum" SELECTED>year (total sales)</option>
		<option value="Max">year (max sales)</option>
	</select>
</body>
</html>

Documentation

Check documentation to learn how to use the components and easily implement them in your applications.