Skip to main content

Chart Widget

The Chart Widget provides a graphical representation of data, allowing users to visualize key metrics in a clear and concise way. This widget is highly customizable to suit various use cases, such as displaying financial metrics like sales and costs.

Alt text

JSON Configuration

Common Widget Properties

PropertyTypeRequiredDefault ValueOptionsDescription
chartobjectYesN/AN/ADefines the chart's settings, including type, labels, data, and colors.
moduleidintegerYesCurrent ModuleN/AThe ID of the module to fetch data from.
queryarrayYesN/AN/ASpecifies the filtering criteria for fetching data.
groupobjectNoN/AN/ADefines how data is aggregated (e.g., sum or count).

Chart Object Properties

PropertyTypeRequiredDefault ValueOptionsDescription
typestringYesN/A"pie", "bar"Specifies the type of chart to display.
labelstringYesN/AN/AThe title of the chart displayed to users.
labelsstring/arrayYesN/ACustom field reference, array of stringsThe labels for each segment of the chart. Can reference a single custom field or be a predefined list of strings.
datastring/arrayYesN/ACustom field reference, array of numbers, or "query"Data values corresponding to each label. Can reference a single custom field, be a predefined list of numbers, or dynamically fetch data using "query".
backgroundColorarrayYesN/AN/ASpecifies colors for each data segment.

Examples

Example 1: Pie Chart for Financial Metrics

This example creates a pie chart titled "Economy" with two data points: Sales and Cost.

{
"chart": {
"type": "pie",
"label": "Economy",
"labels": [
"Salesvalue",
"Cost"
],
"data": [
"[cf1270]",
"[cf1271]"
],
"backgroundColor": [
"green",
"orange"
]
}
}

Example 2: Bar Chart for Financial Metrics

This example creates a bar chart titled "Economy" with the same data as the previous example.

{
"chart": {
"type": "bar",
"label": "Economy",
"labels": [
"Salesvalue",
"Cost"
],
"data": [
"[cf1270]",
"[cf1271]"
],
"backgroundColor": [
"blue",
"red"
]
}
}

Example 3: Query-Based Data Chart

This example demonstrates how to use a query to fetch data for the chart. The data property is set to "query", which instructs the system to dynamically retrieve and aggregate data based on the specified query and group settings.

The labels property points to a custom field containing label information, while the query and group properties handle data filtering and aggregation.

Alt text

{
"moduleid": 40,
"chart": {
"type": "bar",
"label": "Data",
"labels": "cf223",
"data": "query",
"backgroundColor": [
"green",
"orange"
]
},
"query": [
[
"cf214",
">",
0
]
],
"group": {
"cf214": "sum"
}
}

Example 4: Query-Based Chart with Multiple Summed Columns

This example shows how to fetch data using a query and group it based on two columns, summing their values. This configuration is ideal for visualizing datasets where multiple metrics are aggregated.

Alt text

{
"chart": {
"type": "pie",
"label": "Economy",
"data": "query",
"backgroundColor": [
"green",
"orange"
]
},
"relations": {
"module77": {
"parent": 75,
"child": 77,
"relationid": 79
}
},
"query": [
[
"cf1270",
">",
0
]
],
"group": {
"cf1270": "sum",
"cf1271": "sum"
}
}

Explanation:

  • chart: Defines the chart's type and appearance.
  • data: Set to "query" to dynamically fetch data.
  • relations: Specifies relationships between modules for data retrieval.
  • query: Filters the data to include only values greater than 0 in cf1270.
  • group: Aggregates the filtered data, summing up values in both cf1270 and cf1271.
  • backgroundColor: Specifies colors for the chart segments.