You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 16 Next »

Overview

A sparkline is a very small line chart, typically drawn without axes or coordinates. In a simple and highly condensed way, sparklines represent the general shape of a variation, typically over time, in a desired measurement, such as temperature or stock market price.

Sparklines are small enough to be embedded in text, or several sparklines can be grouped together as elements of a small group. 

The typical chart is designed to show as much data as possible and is set off from the flow of text. By contrast, sparklines are intended to be succinct, memorable, and located where they can be most beneficial. 



Requirements and Procedures

Below you will find the steps that need to be followed in order to implement a Sparkline in your project.

  1. A database containing numeric information that will be displayed is
  2. Configure the tables and queries that are going to be used in the
  3. Configure the Draw Environment and implement the necessary code on

Database

In Edit>Datasets>DBs, you need to include the external database by using one of the providers available in the Available Providers list. In this example, we are going to use a SQLite provider in a database called Nwind.


This example database contains many tables in it. However, not all of them will be used in the project. The image below shows all the available tables and highlights the ones that will be used.

Tables and Queries

In Edit>Dataset>Tables/Queries, you can create internal tables and queries for internal usage.

The tables must be mapped to existing ones from the database, as explained in the previous section. Each query is defined for a specific database and may contain a predefined SQL Statement.


Project Configuration

After setting up the tables and queries that you will use, you need to configure one of the tables as the DataSource in the DataGridWindow configuration (1 in image below).

To manipulate a DataGrid control in CodeBehind, the best approach is to use the Control Name field (2 in image below), for the configuration dialog.


Then, you can use that given name to get control of the element and change its properties. 

TDataGridWindow grid = CurrentDisplay.GetDataGrid("Employees"); 
grid.GridControl.SetColumnSparkline("Orders", this.SparklineCollectionDelegate, style);
// SetColumnSparkline parameters - fieldName (string)
//	               - populateCallback (SparklineCollectionDelegate)
//	               - style (string)

A delegate is an object which refers to a method or you can consider it as a variable that holds a reference to a method. It provides a way to know which method is called when an event is triggered. 

A delegate will only call a method which agrees with its signature and return type. A method can be either a static method associated with a class, or it can be an instance method associated with an object. 


Dictionary<int, ArgumentValue[]> mapEmployeeToOrders = null;
private ArgumentValue[] SparklineCollectionDelegate(string fieldName, System.Data.DataRow row)
{
ArgumentValue[] sourceCollection;
int  emplID  =  TK.To< int>(row["EmployeeID"]);
if (!this.mapEmployeeToOrders.TryGetValue(emplID, out sourceCollection)) 
       sourceCollection = new ArgumentValue[0];
return sourceCollection;
}


The Sparkline is updated following the logic seen in the sample code below:

// 	Get data from tables 	// DataTable employees =  @Dataset.Table.Employees.SelectCommand(); 
DataTable orders = @Dataset t.Table.Orders.SelectCommand();
DataTable invoices = @Dataset.Query.Invoices.SelectCommand();
// 	//

this.SetSparkline(style); // Set Style to Sparkline this.mapEmployeeToOrders = new Dictionary<int, ArgumentValue[]>();
foreach (DataRow empl in employees.Rows)
{
int  emplID  =  TK.To<int>(empl["EmployeeID"]);
ist<ArgumentValue> sourceCollection = new List<ArgumentValue>();
foreach (DataRow order in orders.Select("EmployeeID = " + emplID))
{
int  orderID  =  TK.To< int>(order["OrderID"]); ArgumentValue av = new ArgumentValue();
av.Argument  =  order["OrderDate"];  //  x-axis  for  sparkline
foreach (DataRow invoice in invoices.Select("OrderID = " + orderID))
{
double value = TK.To< double >(av.Value);
double  quantity  =  TK.To< double >(invoice["Quantity"]); 
double  unitPrice  =  TK.To< double >(invoice["UnitPrice"]);
av.Value = value + (quantity * unitPrice); // y-axis for sparkline
}
sourceCollection.Add(av);
}
//  map  values  (y-axis)  and  order  date  (x-axis)  to  employee  ID this.mapEmployeeToOrders[emplID] = sourceCollection.ToArray();
}


The Styles available for Sparkline are:

  • Line


  • Area


  • Bar


  • WinLoss

Values are represented by bars that either grow up or go down from an invisible line

  • No labels