DatAInsightsComposer Data Binding
The DatAInsightsComposer can work with a collection of different datasets where each dataset holds data of different type with different properties. This article describes the supported ways to supply data to the DatAInsightsComposer.
Basics
The DatAInsightsComposer learns about its data through its Datasets parameter that can hold one or more DatasetDescriptor objects. Each dataset descriptor contains information about:
- Its unique
stringidentifier and description. - The data item property names and types as a
ListofDatasetFieldDescriptor. - The data items.
The DatAInsightsComposer requires each DatasetDescriptor to have an Id and Fields, but doesn't need the Data to be initially available. The app can load the data on demand, depending on the user prompt or other business logic.
The app can provide data to the DatAInsightsComposer as:
The DatAInsightsComposer sends only dataset field metadata to the AI service. It does not send the actual data items.
Strongly-Typed Model
Using DatAInsightsComposer with strongly-typed data
<TelerikDatAInsightsComposer Datasets="@DAICDatasets"
@bind-Prompt="@DAICPrompt" />
@code {
private string DAICPrompt { get; set; } = "Show all data in tabular format";
private readonly static string[] ProductNames = new string[] { "Phones", "Tablets", "Laptops" };
private List<DatasetDescriptor> DAICDatasets { get; set; } = new()
{
new DatasetDescriptor()
{
Id = "sales-orders",
Label = "Sales Orders",
Description = "Sales orders by category, product, and country",
Fields = new List<DatasetFieldDescriptor>()
{
new() { Name = "Category", Type = DatasetFieldType.String },
new() { Name = "Product", Type = DatasetFieldType.String },
new() { Name = "Country", Type = DatasetFieldType.String },
new() { Name = "OrderDate", Label = "Order Date", Type = DatasetFieldType.Date },
new() { Name = "OrderValue", Label = "Order Value", Type = DatasetFieldType.Number }
}
}
};
protected override void OnInitialized()
{
int dataItemCount = 100;
int categoryCount = 3;
int productCount = 10 + 1;
int countryCount = 5;
Random rnd = Random.Shared;
List<DAICModel> data = new();
for (int i = 1; i <= dataItemCount; i++)
{
int productNumber = Random.Shared.Next(1, productCount);
int categoryNumber = productNumber % categoryCount + 1;
int countryNumber = i % countryCount + 1;
data.Add(new DAICModel()
{
Category = $"Category {categoryNumber}",
Product = $"Product {productNumber}",
Country = $"Country {countryNumber}",
OrderDate = DateOnly.FromDateTime(DateTime.Today.AddDays(-rnd.Next(1, 31)).AddMonths(-rnd.Next(1, 12)).AddYears(-rnd.Next(0, 5))),
OrderValue = rnd.Next(12345, 98765)
});
}
DAICDatasets.First(x => x.Id == "sales-orders").Data = data;
base.OnInitialized();
}
public class DAICModel
{
public string Category { get; set; } = string.Empty;
public string Product { get; set; } = string.Empty;
public string Country { get; set; } = string.Empty;
public DateOnly OrderDate { get; set; }
public decimal OrderValue { get; set; }
}
}
Anonymous Objects
Using DatAInsightsComposer with anonymous objects
<TelerikDatAInsightsComposer Datasets="@DAICDatasets"
@bind-Prompt="@DAICPrompt" />
@code {
private string DAICPrompt { get; set; } = "Show all data in tabular format";
private readonly static string[] ProductNames = new string[] { "Phones", "Tablets", "Laptops" };
private List<DatasetDescriptor> DAICDatasets { get; set; } = new()
{
new DatasetDescriptor()
{
Id = "sales-orders",
Label = "Sales Orders",
Description = "Sales orders by category, product, and country",
Fields = new List<DatasetFieldDescriptor>()
{
new() { Name = "Category", Type = DatasetFieldType.String },
new() { Name = "Product", Type = DatasetFieldType.String },
new() { Name = "Country", Type = DatasetFieldType.String },
new() { Name = "OrderDate", Label = "Order Date", Type = DatasetFieldType.Date },
new() { Name = "OrderValue", Label = "Order Value", Type = DatasetFieldType.Number }
}
}
};
protected override void OnInitialized()
{
int dataItemCount = 100;
int categoryCount = 3;
int productCount = 10 + 1;
int countryCount = 5;
Random rnd = Random.Shared;
List<DAICModel> data = new();
for (int i = 1; i <= dataItemCount; i++)
{
int productNumber = Random.Shared.Next(1, productCount);
int categoryNumber = productNumber % categoryCount + 1;
int countryNumber = i % countryCount + 1;
data.Add(new
{
Category = $"Category {categoryNumber}",
Product = $"Product {productNumber}",
Country = $"Country {countryNumber}",
OrderDate = DateOnly.FromDateTime(DateTime.Today.AddDays(-rnd.Next(1, 31)).AddMonths(-rnd.Next(1, 12)).AddYears(-rnd.Next(0, 5))),
OrderValue = rnd.Next(12345, 98765)
});
}
DAICDatasets.First(x => x.Id == "sales-orders").Data = data;
base.OnInitialized();
}
}
ExpandoObject
Using DatAInsightsComposer with ExpandoObject
@using System.Dynamic
<TelerikDatAInsightsComposer Datasets="@DAICDatasets"
@bind-Prompt="@DAICPrompt" />
@code {
private string DAICPrompt { get; set; } = "Show all data in tabular format";
private readonly static string[] ProductNames = new string[] { "Phones", "Tablets", "Laptops" };
private List<DatasetDescriptor> DAICDatasets { get; set; } = new()
{
new DatasetDescriptor()
{
Id = "sales-orders",
Label = "Sales Orders",
Description = "Sales orders by category, product, and country",
Fields = new List<DatasetFieldDescriptor>()
{
new() { Name = "Category", Type = DatasetFieldType.String },
new() { Name = "Product", Type = DatasetFieldType.String },
new() { Name = "Country", Type = DatasetFieldType.String },
new() { Name = "OrderDate", Label = "Order Date", Type = DatasetFieldType.Date },
new() { Name = "OrderValue", Label = "Order Value", Type = DatasetFieldType.Number }
}
}
};
protected override void OnInitialized()
{
int dataItemCount = 100;
int categoryCount = 3;
int productCount = 10 + 1;
int countryCount = 5;
Random rnd = Random.Shared;
List<object> data = new();
for (int i = 1; i <= dataItemCount; i++)
{
int productNumber = Random.Shared.Next(1, productCount);
int categoryNumber = productNumber % categoryCount + 1;
int countryNumber = i % countryCount + 1;
data.Add(CreateSalesItem(categoryNumber, productNumber, countryNumber));
}
DAICDatasets.First(x => x.Id == "sales-orders").Data = data;
base.OnInitialized();
}
private ExpandoObject CreateSalesItem(int categoryNumber, int productNumber, int countryNumber)
{
Random rnd = Random.Shared;
ExpandoObject item = new ExpandoObject();
IDictionary<string, object?> values = (IDictionary<string, object?>)item;
values.Add("Category", $"Category {categoryNumber}");
values.Add("Product", $"Product {productNumber}");
values.Add("Country", $"Country {countryNumber}");
values.Add("OrderDate", DateOnly.FromDateTime(DateTime.Today.AddDays(-rnd.Next(1, 31)).AddMonths(-rnd.Next(1, 12)).AddYears(-rnd.Next(0, 5))));
values.Add("OrderValue", rnd.Next(1234, 9876));
return item;
}
}
Next Steps
- Configure the DatAInsightsComposer Visuzalization Components
- Implement Best Security Practices
- Manage the DatAInsightsComposer State
- Handle DatAInsightsComposer Events