Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Easy Heading Macro
headingIndent40
navigationTitleOn this page
selectorh2,h3
wrapNavigationTexttrue
navigationExpandOptiondisable-expand-collapse

Info
iconfalse
titleIntroduction

In this page we'll explain how to use Sparklines in DataGrids.

Overview

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

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

Typical charts are Whereas the typical chart is designed to show as much data as possible , and is are set off from the flow of text. In contrast, sparklines are intended to be succinct, memorable, and located where they are discusseddirectly in the text. 


...

Requirements and Procedures

Below you will find the steps that needs to be followed in order to use implement a Sparkline (trend on a grid) in your project.

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

Database

On Edit > Datasets > DBs you will 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.

Database configuration.


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

Tables available in database.

Tables and Queries

On Edit > Dataset > Tables/Queries there is the possibility to create internal Tables and Queries for Internal Usage.

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

The tables must be mapped to tables that already exist in the database, as explained The Tables must be mapped to existing ones from the database, as can be seen in the previous section. The Queries are Each query is defined for a specific database and can (or not) may contain a predefined SQL Statement.

Tables and Query.


Project Configuration

After setting up the Tables tables and Queries queries that you will be used, we must use, you need to configure one of the Tables tables as the DataSource of the in the DataGridWindow component configuration (1).

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

DataGrid Window configuration.


Then, you can use that given name (2) to get control of the element and change its properties. The below is an example. 

Code Block
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 say consider it is as a reference type variable that can hold holds a reference to the methodsa method. It provides a way which tells to know which method is to be called when an event is triggered. 

Note

A delegate will only call only a method which that 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, it doesn’t matter

Below is a callback. The system will always look for a code EXACTLY like this one to create the Sparkline. So if you want to use this feature, you MUST have this code on your code behind.

Code Block
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 A sparkline is updated following the logic as seen in the sample code below:

Code Block
// 	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 styles are:

  • Line

DataGrid Window configuration.


  • Area

DataGrid Window configuration.


  • Bar

DataGrid Window configuration.


  • WinLoss

DataGrid Window configuration.


Note

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