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.
It's possible to group chart data by a certain property. You may use group method or group property in a chart constructor.
<script src="../../codebase/dhtmlxchart.js" type="text/javascript"></script> <link rel="STYLESHEET" type="text/css" href="../../codebase/dhtmlxchart.css"> <script src="../common/companies.js"></script> <script></script> <div id="chart_container" style="width:600px;height:200px;border:1px solid #A4BED4;"></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>var barChart; window.onload = function() { barChart = 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"] } } }); barChart.parse(data, "json"); } function groupCompany() { barChart.group({ by: "#company#", map: { sales: ["#sales#", "sum"] } }); barChart.refresh(); } function groupSum() { barChart.group({ by: "#year#", map: { sales: ["#sales#", "sum"] } }); } function groupMax() { barChart.group({ by: "#year#", map: { sales: ["#sales#", "max"] } }); }