<script type="text/javascript" src="https://www.google.com/jsapi"></script>  
<script>
google.load("visualization", "1", {packages:["corechart"]});  

function renderChart(grid)
{
	var seriesData = grid.getDataArray(['CategoryID','TotalValue']);
	configureChart(seriesData,'chartPanel1','Total Order Value By Category');
	seriesData = grid.getDataArray(['CategoryID','AvgValue']);
	configureChart(seriesData,'chartPanel2','Average Order Value By Category');
}

function configureChart(seriesData, elementId, title)	
{

	var data = new google.visualization.DataTable();  
	data.addColumn('string', 'Label');  
	data.addColumn('number', 'Value');  

	data.addRows(seriesData.length);  

	for (var i=0; i < seriesData.length; i++)
	{
		data.setValue(i, 0, seriesData[i][0]);  
		data.setValue(i, 1, seriesData[i][1]);
	}

	var chart = new google.visualization.PieChart(document.getElementById(elementId));  
	chart.draw(data, {width: 300, height: 200, title:title});  
}				

</script>
<div id="Grid1" style="float:left;padding:10px;"></div>
<div id="chartPanel1" style="float:left;padding:10px;border-left:1pt solid #999;"></div>
<div id="chartPanel2" style="float:left;padding:10px;border-left:1pt solid #999;"></div>
<p style="clear:both"/>
@using DbNetLink.DbNetSuite.UI
@{
    DbNetGrid Grid = new DbNetGrid();
    Grid.ConnectionString = "SamplesDatabase";
    Grid.FromPart = "((Orders inner join [Order Details] on Orders.OrderID = [Order Details].OrderID) inner join Products on Products.ProductId = [Order Details].productid)";
    Grid.ID = "Grid1";
    Grid.ToolbarLocation = DbNetLink.DbNetSuite.GridEditControl.ToolbarOptions.Hidden;
    Grid.GroupBy = true;
    Grid.Theme = Themes.Bootstrap;

    Grid.GridClientEvents.Add(new DbNetLink.DbNetSuite.UI.GridClientEvent(DbNetLink.DbNetSuite.UI.DbNetGrid.ClientEvents.onPageLoaded, "renderChart"));

    DbNetLink.DbNetSuite.UI.GridColumn GC = Grid.GridColumns.Add("Products.CategoryID");
    GC.Label = "Category";
    GC.Lookup = "select CategoryID, CategoryName from categories";

    GC = Grid.GridColumns.Add("([Order Details].UnitPrice * [Order Details].Quantity) as TotalValue");
    GC.Label = "Total Value";
    GC.Aggregate = DbNetLink.DbNetSuite.GridColumn.AggregateValues.Sum;
    GC.Format = "C";

    GC = Grid.GridColumns.Add("([Order Details].UnitPrice * [Order Details].Quantity) as AvgValue");
    GC.Label = "Avg Value";
    GC.Aggregate = DbNetLink.DbNetSuite.GridColumn.AggregateValues.Avg;
    GC.Format = "C"; 
                                                      
    @Html.Raw(DbNetLink.DbNetSuite.UI.MVC.Render(Grid));
};