Difference between revisions of "HTML Presentation Object: Bubble chart"
Jump to navigation
Jump to search
(Created page with "<pre> data0=CreateDataset(Array('Risk', 'Value', 'Cost', 'Category')) data1=AddDatasetRow([data0], 4, 1, 6, 'Category 1') data2=AddDatasetRow([data1], 8, 5, 4, 'Category 2') d...") |
|||
(5 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | Following query contains example data for the bubble chart. Add it to a dataset with name "exampleData". Note that this example needs [[QPR Reporting Expression]] datasource installed. | ||
+ | |||
<pre> | <pre> | ||
− | + | data=CreateDataset(Array('Risk', 'Value', 'Cost', 'Category')) | |
− | + | data=AddDatasetRow([data], 4, 1, 6, 'Category 1') | |
− | + | data=AddDatasetRow([data], 8, 5, 4, 'Category 2') | |
− | + | data=AddDatasetRow([data], 1, 9, 4, 'Category 3') | |
− | + | data=AddDatasetRow([data], 3, 2, 8, 'Category 1') | |
− | + | data=AddDatasetRow([data], 3, 8, 9, 'Category 3') | |
− | + | data=AddDatasetRow([data], 7, 4, 5, 'Category 2') | |
− | + | data=AddDatasetRow([data], 6, 7, 6, 'Category 1') | |
− | + | data=AddDatasetRow([data], 9, 1, 7, 'Category 4') | |
− | + | data=AddDatasetRow([data], 2, 3, 4, 'Category 1') | |
− | + | data=AddDatasetRow([data], 8, 6, 7, 'Category 4') | |
</pre> | </pre> | ||
+ | Paste this example code into a HTML presentation object. | ||
<pre> | <pre> | ||
<div id="container<#uniqueId>"></div> | <div id="container<#uniqueId>"></div> | ||
Line 52: | Line 55: | ||
$("#container<#uniqueId>").empty(); | $("#container<#uniqueId>").empty(); | ||
Highcharts.chart("container<#uniqueId>", { | Highcharts.chart("container<#uniqueId>", { | ||
− | |||
chart: { | chart: { | ||
− | + | type: 'bubble', | |
− | + | plotBorderWidth: 1, | |
− | + | zoomType: 'xy' | |
}, | }, | ||
title: { | title: { | ||
− | + | text: 'Example bubble chart' | |
}, | }, | ||
credits: { | credits: { | ||
Line 65: | Line 67: | ||
}, | }, | ||
xAxis: { | xAxis: { | ||
− | + | gridLineWidth: 1 | |
}, | }, | ||
yAxis: { | yAxis: { | ||
− | + | startOnTick: false, | |
− | + | endOnTick: false, | |
− | + | title: "" | |
}, | }, | ||
− | series: formatDataset(poData<#uniqueId>, {"x": "Value", "y": "Risk | + | series: formatDataset(poData<#uniqueId>, {"x": "Value", "y": "Risk", "z": "Cost"}, "Category", "name", "data") |
}); | }); | ||
} | } | ||
− | function formatDataset( | + | function formatDataset(inputData, mappings, groupColumn, groupAttribute, innerArrayAttribute) { |
− | var | + | var mappedData = []; |
var namesToMap = Object.getOwnPropertyNames(mappings); | var namesToMap = Object.getOwnPropertyNames(mappings); | ||
− | for (var i = 0; i < | + | for (var i = 0; i < inputData.length; i++) { |
var row = {}; | var row = {}; | ||
var mappedColumns = []; | var mappedColumns = []; | ||
for (var j = 0; j < namesToMap.length; j++) { | for (var j = 0; j < namesToMap.length; j++) { | ||
− | row[namesToMap[j]] = | + | row[namesToMap[j]] = inputData[i][mappings[namesToMap[j]]]; |
mappedColumns.push(mappings[namesToMap[j]]); | mappedColumns.push(mappings[namesToMap[j]]); | ||
} | } | ||
− | var dataColumns = Object.getOwnPropertyNames( | + | var dataColumns = Object.getOwnPropertyNames(inputData[i]); |
for (j = 0; j < dataColumns.length; j++) { | for (j = 0; j < dataColumns.length; j++) { | ||
if (mappedColumns.indexOf(dataColumns[j]) == -1) { | if (mappedColumns.indexOf(dataColumns[j]) == -1) { | ||
− | row[dataColumns[j]] = | + | row[dataColumns[j]] = inputData[i][dataColumns[j]]; |
} | } | ||
} | } | ||
− | + | mappedData.push(row); | |
} | } | ||
if (groupColumn == null) { | if (groupColumn == null) { | ||
− | return | + | return mappedData; |
} else { | } else { | ||
var groups = {}; | var groups = {}; | ||
− | for (var i = 0; i < | + | for (var i = 0; i < mappedData.length; i++) { |
− | var groupName = | + | var groupName = mappedData[i][groupColumn]; |
if (groups[groupName] == null) groups[groupName] = []; | if (groups[groupName] == null) groups[groupName] = []; | ||
− | groups[groupName].push( | + | groups[groupName].push(mappedData[i]); |
− | delete | + | delete mappedData[i][groupColumn]; |
} | } | ||
− | var | + | var groupedData = []; |
var groupNames = Object.getOwnPropertyNames(groups); | var groupNames = Object.getOwnPropertyNames(groups); | ||
for (var i = 0; i < groupNames.length; i++) { | for (var i = 0; i < groupNames.length; i++) { | ||
− | var | + | var group = {}; |
− | + | group[groupAttribute] = groupNames[i]; | |
− | + | group[innerArrayAttribute] = groups[groupNames[i]]; | |
− | + | groupedData.push(group); | |
} | } | ||
− | return | + | return groupedData; |
} | } | ||
} | } | ||
</script> | </script> | ||
</pre> | </pre> | ||
+ | |||
+ | [[Category: QPR UI]] |
Latest revision as of 07:50, 6 June 2018
Following query contains example data for the bubble chart. Add it to a dataset with name "exampleData". Note that this example needs QPR Reporting Expression datasource installed.
data=CreateDataset(Array('Risk', 'Value', 'Cost', 'Category')) data=AddDatasetRow([data], 4, 1, 6, 'Category 1') data=AddDatasetRow([data], 8, 5, 4, 'Category 2') data=AddDatasetRow([data], 1, 9, 4, 'Category 3') data=AddDatasetRow([data], 3, 2, 8, 'Category 1') data=AddDatasetRow([data], 3, 8, 9, 'Category 3') data=AddDatasetRow([data], 7, 4, 5, 'Category 2') data=AddDatasetRow([data], 6, 7, 6, 'Category 1') data=AddDatasetRow([data], 9, 1, 7, 'Category 4') data=AddDatasetRow([data], 2, 3, 4, 'Category 1') data=AddDatasetRow([data], 8, 6, 7, 'Category 4')
Paste this example code into a HTML presentation object.
<div id="container<#uniqueId>"></div> <script> var poData<#uniqueId>; var width<#uniqueId>; var height<#uniqueId>; function <#datasetChangeFunction>(datasetIdentifier, datasetChangeCallbackFunction) { if (datasetIdentifier == "exampleData") { datasetChangeCallbackFunction(myDatasetAvailable<#uniqueId>); } } function myDatasetAvailable<#uniqueId>(datasetData) { if (datasetData == null || datasetData.sheets == null || datasetData.sheets.length == 0 || datasetData.sheets[0] == null || datasetData.sheets[0].values == null || datasetData.sheets[0].values.length == 0) return; poData<#uniqueId> = []; for (var row = 1; row < datasetData.sheets[0].values[0].length; row++) { var rowObject = {}; for (var column = 0; column < datasetData.sheets[0].values.length; column++) { rowObject[datasetData.sheets[0].values[column][0].attribute] = datasetData.sheets[0].values[column][row].value; } poData<#uniqueId>.push(rowObject); } drawPO<#uniqueId>(); } function <#resizeFunction>(newWidth, newHeight) { width<#uniqueId> = newWidth; height<#uniqueId> = newHeight; $("#container<#uniqueId>").width(newWidth); $("#container<#uniqueId>").height(newHeight); drawPO<#uniqueId>(); } function drawPO<#uniqueId>() { if (poData<#uniqueId> == null || width<#uniqueId> == null) return; $("#container<#uniqueId>").empty(); Highcharts.chart("container<#uniqueId>", { chart: { type: 'bubble', plotBorderWidth: 1, zoomType: 'xy' }, title: { text: 'Example bubble chart' }, credits: { enabled: false }, xAxis: { gridLineWidth: 1 }, yAxis: { startOnTick: false, endOnTick: false, title: "" }, series: formatDataset(poData<#uniqueId>, {"x": "Value", "y": "Risk", "z": "Cost"}, "Category", "name", "data") }); } function formatDataset(inputData, mappings, groupColumn, groupAttribute, innerArrayAttribute) { var mappedData = []; var namesToMap = Object.getOwnPropertyNames(mappings); for (var i = 0; i < inputData.length; i++) { var row = {}; var mappedColumns = []; for (var j = 0; j < namesToMap.length; j++) { row[namesToMap[j]] = inputData[i][mappings[namesToMap[j]]]; mappedColumns.push(mappings[namesToMap[j]]); } var dataColumns = Object.getOwnPropertyNames(inputData[i]); for (j = 0; j < dataColumns.length; j++) { if (mappedColumns.indexOf(dataColumns[j]) == -1) { row[dataColumns[j]] = inputData[i][dataColumns[j]]; } } mappedData.push(row); } if (groupColumn == null) { return mappedData; } else { var groups = {}; for (var i = 0; i < mappedData.length; i++) { var groupName = mappedData[i][groupColumn]; if (groups[groupName] == null) groups[groupName] = []; groups[groupName].push(mappedData[i]); delete mappedData[i][groupColumn]; } var groupedData = []; var groupNames = Object.getOwnPropertyNames(groups); for (var i = 0; i < groupNames.length; i++) { var group = {}; group[groupAttribute] = groupNames[i]; group[innerArrayAttribute] = groups[groupNames[i]]; groupedData.push(group); } return groupedData; } } </script>