Array DataSource

Introduction

Example: A simple chart

A simple chart

<?php
require "../razorflow.php";

$ds = new ArrayDataSource ();
$ds->setData(array(
		'store' => 'text',
		'genre' => 'text',
		'name' => 'text',
		'sales' => 'number' 
	),
	array(
		array('North', 'Alternative', "Radiohead", 55),
		array('North', 'Classical', "Beethoven", 37),
		array('North', 'Electronic', "Daft Punk", 68),
		array('South', 'Electronic', "Justice", 68),
		array('South', 'Classical', "Bach", 29),
		array('South', 'Alternative', "Coldplay", 18)
	)
);
$ds->initialize();


$chart = new ChartComponent();
$chart->setCaption("Sales by Genre");
$chart->setDataSource($ds);
$chart->setLabelExpression("Genre",  // The name of the X-Axis
					      'genre'); // Label Expression
$chart->addSeries('Sales',  // Name of the series
				  'sales'); // Expression
Dashboard::addComponent($chart);

Dashboard::Render();

Example: A chart with drill-down

A simple chart

<?php
require "../razorflow.php";

$ds = new ArrayDataSource ();
$ds->setData(array(
		'store' => 'text',
		'genre' => 'text',
		'name' => 'text',
		'sales' => 'number' 
	),
	array(
		array('North', 'Alternative', "Radiohead", 55),
		array('North', 'Classical', "Beethoven", 37),
		array('North', 'Electronic', "Daft Punk", 68),
		array('South', 'Electronic', "Justice", 68),
		array('South', 'Classical', "Bach", 29),
		array('South', 'Alternative', "Coldplay", 18)
	)
);
$ds->initialize();

$chart = new ChartComponent();
$chart->setCaption("Sales Drilldown");
$chart->setDataSource($ds);
$chart->setLabelExpression("Selection", 'store', array('drillPath' => array('store', 'genre', 'name')));
$chart->addSeries('Sales',  // Name of the series
				  'sales'); // Expression
Dashboard::addComponent($chart);

Dashboard::Render();

Example: A chart with time-ranging

A simple chart

<?php
require "../razorflow.php";


$ds = new ArrayDataSource ();
$ds->setData(array(
		'store' => 'text',
		'genre' => 'text',
		'name' => 'text',
		'sales' => 'number',
		'sale_time' => 'datetime'
	),
	array(
		array('North', 'Alternative', "Radiohead", 55, new DateTime("4/4/2013")),
		array('North', 'Classical', "Beethoven", 37, new DateTime("5/5/2013")),
		array('North', 'Electronic', "Daft Punk", 68, new DateTime("6/6/2013")),
		array('South', 'Electronic', "Justice", 68, new DateTime("5/5/2013")),
		array('South', 'Classical', "Bach", 29, new DateTime("6/6/2013")),
		array('South', 'Alternative', "Coldplay", 18, new DateTime("7/7/2013"))
	)
);

$ds->initialize();

$chart = new ChartComponent();
$chart->setCaption("Sales Drilldown");
$chart->setDataSource($ds);
$chart->setLabelExpression("Sale Time", 'sale_time', array(
	'timestampRange' => true,
	'timeUnit' => 'month',
	'autoDrill' => true,
	'customTimeUnitPath' => array('month', 'day')
));
$chart->addSeries('Sales',  // Name of the series
				  'sales'); // Expression
Dashboard::addComponent($chart);

Dashboard::Render();

Example: A filter and table

A simple chart

<?php
require "../razorflow.php";

$ds = new ArrayDataSource ();

$ds = new ArrayDataSource ();
$ds->setData(array(
		'store' => 'text',
		'genre' => 'text',
		'name' => 'text',
		'amount' => 'number',
		'sale_time' => 'datetime'
	),
	array(
		array('North', 'Alternative', "Radiohead", 55, new DateTime("4/4/2013")),
		array('North', 'Classical', "Beethoven", 37, new DateTime("5/5/2013")),
		array('North', 'Electronic', "Daft Punk", 68, new DateTime("6/6/2013")),
		array('South', 'Electronic', "Justice", 68, new DateTime("5/5/2013")),
		array('South', 'Classical', "Bach", 29, new DateTime("6/6/2013")),
		array('South', 'Alternative', "Coldplay", 18, new DateTime("7/7/2013")),
		array('North', 'Alternative', "Radiohead", 55, new DateTime("4/4/2013")),
		array('North', 'Classical', "Beethoven", 37, new DateTime("5/5/2013")),
		array('North', 'Electronic', "Daft Punk", 68, new DateTime("6/6/2013")),
		array('South', 'Electronic', "Justice", 68, new DateTime("5/5/2013")),
		array('South', 'Classical', "Bach", 29, new DateTime("6/6/2013")),
		array('South', 'Alternative', "Coldplay", 18, new DateTime("7/7/2013"))
	)
);
$ds->initialize();


$filter = new AutoFilterComponent();
$filter->setDataSource($ds);
$filter->addTimeRangeFilter("Sale Time", 'sale_time');
$filter->addSelectFilter("Store", 'store');
$filter->addMultiSelectFilter("Genre", 'genre');
Dashboard::addComponent($filter);

$table = new TableComponent();
$table->setCaption("Sales Table");
$table->setDataSource($ds);
$table->addColumn("Store", 'store');
$table->addColumn("Genre", 'genre');
$table->addColumn("Artist Name", 'name');
$table->addColumn("Amount", 'amount');
$table->addColumn("Sales Time", 'sale_time');
Dashboard::addComponent($table);

$filter->addFilterTo($table);

Dashboard::Render();

Start building interactive, mobile-friendly Dashboards in PHP. See DemosDownload