Difference between revisions of "HTML Presentation Object: Bubble chart"

From Mea Wiki
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...")
 
m
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>
 
data0=CreateDataset(Array('Risk', 'Value', 'Cost', 'Category'))
 
data0=CreateDataset(Array('Risk', 'Value', 'Cost', 'Category'))
Line 13: Line 15:
 
</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',
+
      type: 'bubble',
        plotBorderWidth: 1,
+
      plotBorderWidth: 1,
        zoomType: 'xy'
+
      zoomType: 'xy'
 
     },
 
     },
 
     title: {
 
     title: {
        text: 'Example bubble chart with random data'
+
      text: 'Example bubble chart with random data'
 
     },
 
     },
 
     credits: {
 
     credits: {
Line 65: Line 67:
 
     },
 
     },
 
     xAxis: {
 
     xAxis: {
        gridLineWidth: 1
+
      gridLineWidth: 1
 
     },
 
     },
 
     yAxis: {
 
     yAxis: {
        startOnTick: false,
+
      startOnTick: false,
        endOnTick: false,
+
      endOnTick: false,
        title: ""
+
      title: ""
 
     },
 
     },
 
     series: formatDataset(poData<#uniqueId>, {"x": "Value", "y": "Risk", "x": "Value", "z": "Cost"}, "Category", "name", "data")
 
     series: formatDataset(poData<#uniqueId>, {"x": "Value", "y": "Risk", "x": "Value", "z": "Cost"}, "Category", "name", "data")

Revision as of 19:57, 6 December 2017

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.

data0=CreateDataset(Array('Risk', 'Value', 'Cost', 'Category'))
data1=AddDatasetRow([data0], 4, 1, 6, 'Category 1')
data2=AddDatasetRow([data1], 8, 5, 4, 'Category 2')
data3=AddDatasetRow([data2], 1, 9, 4, 'Category 3')
data4=AddDatasetRow([data3], 3, 2, 8, 'Category 1')
data5=AddDatasetRow([data4], 3, 8, 9, 'Category 3')
data6=AddDatasetRow([data5], 7, 4, 5, 'Category 2')
data7=AddDatasetRow([data6], 6, 7, 6, 'Category 1')
data8=AddDatasetRow([data7], 9, 1, 7, 'Category 4')
data9=AddDatasetRow([data8], 2, 3, 4, 'Category 1')
data10=AddDatasetRow([data9], 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 with random data'
    },
    credits: {
      enabled: false
    },
    xAxis: {
      gridLineWidth: 1
    },
    yAxis: {
      startOnTick: false,
      endOnTick: false,
      title: ""
    },
    series: formatDataset(poData<#uniqueId>, {"x": "Value", "y": "Risk", "x": "Value", "z": "Cost"}, "Category", "name", "data")
  });
}

function formatDataset(data, mappings, groupColumn, groupAttribute, innerArrayAttribute) {
  var output = [];
  var namesToMap = Object.getOwnPropertyNames(mappings);
  for (var i = 0; i < data.length; i++) {
    var row = {};
    var mappedColumns = [];
    for (var j = 0; j < namesToMap.length; j++) {
      row[namesToMap[j]] = data[i][mappings[namesToMap[j]]];
      mappedColumns.push(mappings[namesToMap[j]]);
    }
    var dataColumns = Object.getOwnPropertyNames(data[i]);
    for (j = 0; j < dataColumns.length; j++) {
      if (mappedColumns.indexOf(dataColumns[j]) == -1) {
        row[dataColumns[j]] = data[i][dataColumns[j]];
      }
    }
    output.push(row);
  }

  if (groupColumn == null) {
    return output;
  } else {
    var groups = {};
    for (var i = 0; i < output.length; i++) {
      var groupName = output[i][groupColumn];
      if (groups[groupName] == null) groups[groupName] = [];
      groups[groupName].push(output[i]);
      delete output[i][groupColumn];
    }
    var outputArray = [];
    var groupNames = Object.getOwnPropertyNames(groups);
    for (var i = 0; i < groupNames.length; i++) {
      var groupItem = {};
      groupItem[groupAttribute] = groupNames[i];
      groupItem[innerArrayAttribute] = groups[groupNames[i]];
      outputArray.push(groupItem);
    }
    return outputArray;
  }
}
</script>