HTML Presentation Object: Gantt chart

From Mea Wiki
Revision as of 17:53, 16 December 2017 by Ollvihe (talk | contribs) (Created page with "The following query contains example data for the gantt chart. Add it to a HTML presentation object's dataset with name "exampleData". Note that this example needs QPR Repor...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The following query contains example data for the gantt chart. Add it to a HTML presentation object's dataset with name "exampleData". Note that this example needs QPR Reporting Expression datasource installed.

data0=CreateDataset(Array('TaskName', 'StartDate', 'EndDate', 'PlannedStartDate', 'PlannedEndDate', 'Progress'))
data1=AddDatasetRow([data0], 'Project Task 1', NewDatetime(2017,1,1), NewDatetime(2017,2,15), NewDatetime(2017,1,1), NewDatetime(2017,2,15), 35)
data2=AddDatasetRow([data1], 'Project Task 2', NewDatetime(2017,2,1), NewDatetime(2017,4,1), NewDatetime(2017,1,1), NewDatetime(2017,2,15), 90)
data3=AddDatasetRow([data2], 'Project Task 3', NewDatetime(2017,4,1), NewDatetime(2017,6,1), NewDatetime(2017,1,1), NewDatetime(2017,2,15), 15)
data4=AddDatasetRow([data3], 'Project Task 4', NewDatetime(2017,1,1), NewDatetime(2017,2,15), NewDatetime(2017,1,1), NewDatetime(2017,2,15), 35)
data5=AddDatasetRow([data4], 'Project Task 5', NewDatetime(2017,2,1), NewDatetime(2017,4,1), NewDatetime(2017,1,1), NewDatetime(2017,2,15), 90)
data6=AddDatasetRow([data5], 'Project Task 6', NewDatetime(2017,4,1), NewDatetime(2017,6,1), NewDatetime(2017,1,1), NewDatetime(2017,2,15), 15)
data7=AddDatasetRow([data6], 'Project Task 7', NewDatetime(2017,1,1), NewDatetime(2017,2,15), NewDatetime(2017,1,1), NewDatetime(2017,2,15), 35)
data8=AddDatasetRow([data7], 'Project Task 8', NewDatetime(2017,2,1), NewDatetime(2017,4,1), NewDatetime(2017,1,1), NewDatetime(2017,2,15), 90)
data9=AddDatasetRow([data8], 'Project Task 9', NewDatetime(2017,4,1), NewDatetime(2017,6,1), NewDatetime(2017,1,1), NewDatetime(2017,2,15), 15)

Use the following HTML code:

<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);
  }
  for (var i = 0; i < poData<#uniqueId>.length; i++) { 
    poData<#uniqueId>[i]["StartDate"] = parseInt(poData<#uniqueId>[i]["StartDate"].replace("/Date(", "").replace(")/", ""));
    poData<#uniqueId>[i]["EndDate"] = parseInt(poData<#uniqueId>[i]["EndDate"].replace("/Date(", "").replace(")/", ""));
    poData<#uniqueId>[i]["PlannedStartDate"] = parseInt(poData<#uniqueId>[i]["PlannedStartDate"].replace("/Date(", "").replace(")/", ""));
    poData<#uniqueId>[i]["PlannedEndDate"] = parseInt(poData<#uniqueId>[i]["PlannedEndDate"].replace("/Date(", "").replace(")/", ""));
    poData<#uniqueId>[i]["ProgressPoint"] = (new Date(poData<#uniqueId>[i]["StartDate"] + (poData<#uniqueId>[i]["EndDate"] - poData<#uniqueId>[i]["StartDate"]) * poData<#uniqueId>[i]["Progress"] / 100)).getTime();
  }
  drawPO<#uniqueId>();
}
 
function <#resizeFunction>(newWidth, newHeight) {debugger;
  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: 'columnrange',
        inverted: true
    },
    title: {
    text: 'Gantt chart' },
    xAxis: { type: "category" },
    credits: { enabled: false },
    yAxis: {
      type: 'datetime',
      opposite: true,
        dateTimeLabelFormats: {
          day: '%d/%m', week: '%d/%m', month: '%m/%Y', year: '%Y'
        },
        title: ""
    },

    tooltip: {
        useHTML: true,
        formatter: function () {
            return  "<span style='font-weight: bold;font-size:125%;'>" + this.point.name + "</span></br>Actual: <b>" + (new Date(this.point.low)).toLocaleDateString() + "</b> - <b>" + (new Date(this.point.high)).toLocaleDateString() + "</b></br>" +
              "Planned: <b>" + (new Date(this.point.PlannedStartDate)).toLocaleDateString() + "</b> - <b>" + (new Date(this.point.PlannedEndDate)).toLocaleDateString() + "</b></br>" + 
              "Progress: <b>" + this.point.progress + "%</b>";
        }
    },
    legend: { enabled: false },
    series: [{
      color: "#296293",
      stacking: "normal",
        data: formatDataset(poData<#uniqueId>, {"low": "StartDate", "high": "ProgressPoint", "progress": "Progress", "name": "TaskName"}),
         dataLabels: {
            enabled: true,
            align: 'center',
            inside: true,
            format: '{point.progress} %',
            style: {
                fontSize: '13px'
            }
        }
    },
    {
      color: "#3277b2",
      stacking:"normal",
        data: formatDataset(poData<#uniqueId>, {"low": "ProgressPoint", "high": "EndDate", "progress": "Progress", "name": "TaskName"}),
         dataLabels: {
            enabled: true,
            align: 'center',
            inside: true,
            format: '',
            style: {
                fontSize: '13px'
            }
        }
    }
    ]
});
}

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>