Wijmo 5 - FlexGrid and FlexChart

by Joel Parks

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.grapecity.com/wijmo/5.latest/styles/wijmo.min.css">
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.grid.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.chart.min.js"></script>
<!--<div class="container">
  <div id="theGrid"></div>
</div>-->
<div class="container">
	<div class="box box-1">box 1</div>
	<div class="box box-2">
	  <div id="theGrid"></div>
	</div>
	<div class="box box-3">box 3</div>
</div>

CSS

.wj-flexgrid {
  margin: 12px;
}

html,
body {
	height: 100%;
}

.container {
	height: 100%;
  min-height: 100%;
	display: flex;
	flex-direction: column;
}

.box {
		text-align: center;
		color: white;
		font-family: sans-serif;
		padding: 20px;
		display: flex;
		flex-direction: column;
    justify-content: center;
}

.box-1 {
		background-color: green;
		height: 60px;
}

	.box-2 {
		background-color: blue;
		flex: 1;
	}

	.box-3 {
		background-color: red;
		height: 60px;
	}

JavaScript

onload = function() {

    // create some random data
    var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
        data = [];
    for (var i = 0; i < countries.length; i++) {
        data.push({
            country: countries[i],
            downloads: Math.round(Math.random() * 20000),
            sales: Math.random() * 10000,
            expenses: Math.random() * 5000
        });
    }

    // create CollectionView on the data (so grid and chart stay in sync)
    var view = new wijmo.collections.CollectionView(data);

    // initialize the grid
    var grid = new wijmo.grid.FlexGrid('#theGrid', {
        columns: [
        	{ binding: 'country', header: 'Country' },
          { binding: 'sales', header: 'Sales' },
          { binding: 'expenses', header: 'Expenses' },
          { binding: 'downloads', header: 'Downloads', format: 'n0' }
				],
        autoGenerateColumns: false,
        itemsSource: view,
        selectionMode: wijmo.grid.SelectionMode.Row
    });

    // initialize the chart
    var chart = new wijmo.chart.FlexChart('#theChart', {
        itemsSource: view,
        bindingX: 'country',
        series: [
        	{ binding: 'sales', name: 'Sales' },
          { binding: 'expenses', name: 'Expenses' },
          { binding: 'downloads', name: 'Downloads', chartType: wijmo.chart.ChartType.LineSymbols }
        ],
        selectionMode: wijmo.chart.SelectionMode.Point
    });
}