JSON data source

Data source

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div id="pivot-container"></div>

JavaScript

var jsonData = [{
    type: 0,
    'date agg': '2017-01-01'
  },
  {
    type: 0,
    'date agg': '2017-01-02'
  },
  {
    type: 0,
    'date agg': '2017-01-03'
  },
  {
    type: 1,
    'date agg': '2017-01-04'
  },
  {
    type: 1,
    'date agg': '2017-01-05'
  },
  {
    type: 1,
    'date agg': '2017-01-06'
  },
];

var pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  customizeCell: customizeCellFunction,
  report: {
    dataSource: {
      data: jsonData,
      mapping: {
        type: {
          type: "number"
        },
        'date agg': {
          type: "date string"
        }
      }
    },
    slice: {
      rows: [{
        uniqueName: "type"
      }],
      columns: [{
        uniqueName: "[Measures]"
      }, ],
      measures: [{
          uniqueName: "count",
          formula: "count('date agg')",
          grandTotalCaption: "Count"
        },
        {
          caption: "First visit",
          uniqueName: "firstvisit",
          formula: "min('date agg')"
        },
        {
          caption: "Last visit",
          uniqueName: "lastvisit",
          formula: "max('date agg')"
        },
        {
          uniqueName: "special",
          formula: "distinctcount('type') / distinctcount('date agg')",
          grandTotalCaption: "Special"
        }
      ],
    },
  },
});

function customizeCellFunction(cell, data) {
  if (data.measure != undefined && (data.measure.uniqueName == 'lastvisit' ||
      data.measure.uniqueName == 'firstvisit') && !isNaN(data.value)) {
    cell.text = new Date(data.value).toLocaleDateString();
  }
}