Render a D3JS Bar chart - Part 2


function getCategoryData(viewName, dataColumn, getChildren, key) {
	var v = database.getView(viewName);
	var nav;
	if (key) {
		nav = v.createViewNavFromCategory(key);
	} else {
	   nav= v.createViewNav();
	}
	var ve = nav.getFirst();
	var isFirst = true;
	var result = "[";
	while (ve) {
		if (!ve.isTotal()) {
			var curData = ve.getColumnValues();
			if (!isFirst) {
				result += ",";
			}
			result += "{label : \"";
			if (key) {
				result += curData[1];
			} else {
				result += curData[0];	
			}			
			result += "\", value : ";
			result += curData[dataColumn];
			/* for 2 level categories we fetch additional data */
			if (getChildren) {
				var childve = nav.getChild();
				var firstChild = true;
				result += ", children : [";
				while (childve) {
					var childData = childve.getColumnValues();
					if (!firstChild) {
						result += ",";
					}
					result += "{label : \"";
					result += childData[1];
					result += "\", value : ";
					result += childData[dataColumn];
					result += "}";			
					firstChild = false;
					childve = nav.getNextSibling(childve);
				}
				result += "]"
			}
			result += "}";			
			isFirst = false;
		}		
		ve = nav.getNextSibling(ve);
	}
	result += "]";
	return result;
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...