Rounding dates in CSV and JSON using the mapping.interval property

Mapping configuration

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<div id="pivot-container"></div>

CSS

@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      data: getData(),
      mapping: {
        "Date": [
        	{
          	uniqueName: "DateOriginal",
          	type: "datetime",
          	caption: "Original date"
        	},
          {
          	uniqueName: "DateRoundedDay",
          	type: "datetime",
          	caption: "Date rounded by 1 day interval",
            interval: "1d"
        	},
          {
          	uniqueName: "DateRoundedYear",
          	type: "datetime",
          	caption: "Date rounded by 1 year interval",
            interval: "y"
        	}
        ]
      }
    },
    slice: {
      rows: [
            {
                uniqueName: "DateOriginal"
            },
            {
                uniqueName: "DateRoundedDay"
            },
            {
                uniqueName: "DateRoundedYear"
            }
        ]
    },
    options: {
    	grid: {
      	type: "flat"
      }
    }
  }
});

function getData() {
  return [
    {
      "Date": "2021-05-25T21:30:00",
      "Price": 200
    },
    {
      "Date": "2020-01-11T23:55:00",
      "Price": 150
    },
    {
      "Date": "2021-03-08T22:45:00",
      "Price": 300
    }
  ]
}