Created
November 6, 2012 17:54
-
-
Save vgrem/4026341 to your computer and use it in GitHub Desktop.
Google Chart Tools - draw chart for data returned from Sharepoint Web Services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOrgChartDataLoaded(orgChartData, status) { | |
var data = new google.visualization.DataTable(); | |
data.addColumn('string', 'Name'); | |
data.addColumn('string', 'Parent'); | |
data.addColumn('string', 'ToolTip'); | |
var chartFieldNames = { Title: generateOwsFieldName(google.OrgChartData.TitleFieldName), | |
Tooltip: generateOwsFieldName(google.OrgChartData.TooltipFieldName), | |
Parent: generateOwsFieldName(google.OrgChartData.ParentFieldName), | |
Properties: generateOwsFieldName(google.OrgChartData.StyleFieldName) | |
}; | |
var orgChartRowProperties = {}; | |
var orgChartDataRows = []; | |
var orgChartResult = ($.browser.msie ? orgChartData.responseXML : orgChartData.responseText); | |
$(orgChartResult).find("z\\:row").each(function (rowIndex) { | |
var orgChartRow = []; | |
//if ($(this).attr(chartFieldNames.Layout) == undefined) | |
orgChartRow[0] = $(this).attr(chartFieldNames.Title); | |
//else { | |
// orgChartRow[0] = { v: $(this).attr(chartFieldNames.Title), f: $(this).attr(chartFieldNames.Layout) }; | |
//} | |
orgChartRow[1] = ($(this).attr(chartFieldNames.Parent) != undefined ? $(this).attr(chartFieldNames.Parent).split(';#')[1] : ''); | |
orgChartRow[2] = $(this).attr(chartFieldNames.Tooltip); | |
if ($(this).attr(chartFieldNames.Properties) != undefined) { | |
orgChartRowProperties[rowIndex] = parseChartRowProperties($(this).attr(chartFieldNames.Properties)); | |
} | |
orgChartDataRows[orgChartDataRows.length] = orgChartRow; | |
}); | |
data.addRows(orgChartDataRows); | |
$.each(orgChartRowProperties, function (rowIndex, rowProperty) { | |
data.setRowProperties(parseInt(rowIndex), rowProperty); | |
}); | |
var chart = new google.visualization.OrgChart(document.getElementById('orgChartCanvas')); | |
chart.draw(data, { allowHtml: true, allowCollapse: true }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment