docs(datasource-sql): document introspection process
Value charts simply are charts that display a single value.
They can be added to the Dashboard using the addChart method on the agent object
// Add a chart to the Dashboard pageagent.addChart('monthlyRecuringRevenue',async (context, resultBuilder) => {// Request the sum of the "amount" field of all the records in the "payments" collectionconstaggregation= { operation:'Sum', field:'amount' };constfilter= { conditionTree: { field:'status', operator:'equal', value:'paid' } };constrows=awaitcontext.dataSource.getCollection('payments').aggregate(filter, aggregation);// Return the result to the chartreturnresultBuilder.value(rows[0].value);});
Or to the Analytics page of a collection using the addChart method on the collection object
// Add a chart to the Analytics page of the collection "customers"agent.customizeCollection('customers', collection => {collection.addChart('monthlyRecuringRevenue',async (context, resultBuilder) => {// Request the sum of the "amount" field of the records in the "payments" collection matching// current customerconstaggregation= { operation:'Sum', field:'amount' };constfilter= { conditionTree: { aggregator:'And', conditions: [ { field:'status', operator:'equal', value:'paid' }, { field:'customer:id', operator:'equal', value:context.recordId }, ], }, };constrows=awaitcontext.dataSource.getCollection('payments').aggregate(filter, aggregation);// Return the result to the chartreturnresultBuilder.value(rows[0].value); });});
Optionally, an older value can be provided to the resultBuilder to display a growth percentage on the top right of the widget as in the following screenshot: