DHTMLX Docs & Samples Explorer

Example (Grouping)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Chart</title>
 
	<script src="../../codebase/dhtmlxchart.js" type="text/javascript"></script>
	<link rel="STYLESHEET" type="text/css" href="../../codebase/dhtmlxchart.css">
 
	<style>
		.dhx_chart_title{
			padding-left:3px
		}
	</style>
</head>
<body>
	<h1>Chart</h1>
 
	<div id="chart_container" style="width:500px;height:300px;border:1px solid #A4BED4;"></div>
 
	<script>
	var barChart =  new dhtmlXChart({
		view:"bar",
		container:"chart_container",
	    value:"#sales#",
		label:"#id#",
		sort:{
			by:"#id#",
			as:"string",
			dir:"asc"
		},
		group:{
			by:"#year#",
			map:{
				sales:["#sales#","sum"]
			}
		}
	})
	barChart.load("../common/stat.xml");
 
 
	function  groupA(){
		barChart.group({
			by:"#company#",
			map:{
				sales:["#sales#","sum"]
			}
		});
	}	
 
	function  groupB(){
		barChart.group({
			by:"#year#",
			map:{
				sales:["#sales#","sum"]
			}
		});
	}	
 
	function  groupC(){
		barChart.group({
			by:"#year#",
			map:{
				sales:["#sales#","max"]
			}
		});
	}
	function sort_asc(){
		barChart.define("sort",{
			by:"#id#",
			dir:"asc"
		});
		barChart.render();
	}
	function sort_dsc(){
		barChart.define("sort",{
			by:"#id#",
			dir:"dsc"
		});
		barChart.render();
	}
	</script>
	<input type="button" name="some_name" value="group by Company" onclick="groupA();">
	<input type="button" name="some_name" value="group by Year (total sales)" onclick="groupB();">
	<input type="button" name="some_name" value="group by Year (max sales)" onclick="groupC();">
	<br/>
	<input type="button" name="some_name" value="sort Asc" onclick="sort_asc();">
	<input type="button" name="some_name" value="sort Desc" onclick="sort_dsc();">
 
</body>
</html>