Search K
Appearance
On this page we will explain in detail how to build different types of metrics to display on your dashboards.
Every metric implements either the IBasicMetric
or the ITimeSpanMetric
interface, depending on the metrics characteristics. Metrics further need a reference type that denotes its underlying entity model class, designated by TEntity
.
All metrics need to implement the following abstract methods:
IQueryable<TEntity> GetQueryable()
Return the queryable of the associated entity type. We recommend injecting the appropriate DbContext
for easy access.string Title()
Set the title the metric should be displayed with.Implement a class that inherits from DistributionMetric<TEntity>
. Ensure all abstract members of the parent class are implemented, for a distribution metric this includes:
string GroupByProperty
Set the property of the entity to group the data set by.GroupBy Considerations
The property to group by should have a manageable number of categories, otherwise the resulting pie chart may be difficult to interpret.
An example would be setting up a metric that illustrates the distribution of work models among employees:
using Linkerion.Centias.Displayables.Metrics;
public class EmployeeWorkModelChart(ApplicationDbContext context):
DistributionMetric<Employee>
{
protected override string Title() => "Employee Work Models";
protected override IQueryable<Employee> GetQueryable()
=> context.Employees;
protected override string GroupByProperty => "WorkModel";
}
Implement a class that inherits from ProgressionMetric<TEntity>
. Ensure all abstract members of the parent class are implemented, for a progression metric this includes:
int Target()
Set the numeric target value that the progress will be calculated against.Let's say we have a target number of sales we want to achieve, an example metric could look like this:
using Linkerion.Centias.Displayables.Metrics;
public class SalesProgress(ApplicationDbContext context):
ProgressMetric<Sale>
{
protected override string Title() => "Number of Sales";
protected override int Target() => 100;
protected override IQueryable<Sale> GetQueryable()
=> context.Sales;
}
Implement a class that inherits from TrendMetric<TEntity>
. Ensure all abstract members of the parent class are implemented, for a trend metric this includes:
string GroupByProperty
Set the property of the entity to group the data set by. This must be a chronological value.Please note that for the metric to differentiate entities chronologically, some kind of timestamp needs to be present.
In the case of our example each Sale
entity has a creation date attached to it in the form of the DateTimeOffset
field CreatedAt
.
To track daily sales numbers over time, we use a trend metric:
using Linkerion.Centias.Displayables.Metrics;
public class SalesTrend(ApplicationDbContext context) : TrendMetric<Sale>
{
protected override string GroupByProperty => "CreatedAt";
protected override string Title() => "Sales per Day";
protected override IQueryable<Sale> GetQueryable()
=> context.Sales;
}
Implement a class that inherits from ValueMetric<TEntity>
. Ensure all abstract members of the parent class are implemented, for a value metric this includes:
string GroupByProperty
Set the property of the entity to group the data set by. This must be a chronological value.Please note that for the metric to differentiate entities chronologically, some kind of timestamp needs to be present. See Trend Metric for an example.
To track sales numbers and their percentage changes over time we use a value metric:
using Linkerion.Centias.Displayables.Metrics;
public class SalesMetric(ApplicationDbContext context): ValueMetric<Sale>
{
protected override string GroupByProperty => "CreatedAt";
protected override string Title() => "Latest Sales";
protected override IQueryable<Sale> GetQueryable()
=> context.Sales;
}