StpDasboard
StpDasboard: A Strapi plugin for dynamic dashboards with multi-data charts (Line, Bar, Area). Edit JSON, SQL queries, and titles via a user-friendly interface. Visualize data in full-screen or delete charts effortlessly
StpDasboard is a plugin that allows you to visualize a dashboard in Strapi with multiple charts, including Bar, Line, Area, and more. This plugin enhances the Strapi admin panel by providing a comprehensive and customizable interface for displaying various types of data visualizations. With Ksdasboard, you can easily create and manage dashboards to monitor key metrics and insights directly within your Strapi environment.
🎉 Supports Strapi version 5 🎉
Key Features of StpDasboard: 1. Multiple Chart Types: - Supports various chart types such as Bar, Line, Area, Pie, and more. - Allows you to choose the best visualization for your data.
Customizable Dashboards:
- Create and customize multiple dashboards to suit your needs.
- Arrange and resize charts to create an optimal layout.
Real-Time Data:
- Visualize real-time data updates to keep your dashboards current.
- Connect to different data sources to fetch and display data dynamically.
User-Friendly Interface:
- Intuitive interface for adding, editing, and managing charts.
- Easy-to-use configuration options for each chart type.
Integration with Strapi:
- Seamlessly integrates with Strapi's admin panel. Utilizes Strapi's content management capabilities to fetch and display data.
Install & Configure
To install and configure the StpDasboard plugin for Strapi, follow these steps: 1. Open your terminal and navigate to your Strapi project directory. 2. Run the following command to install the StpDasboard plugin:
1```shell
2npm i strapi-plugin-dashboard
3```
Update the Plugin Configuration File: - Navigate to the
config\plugins.ts
file in your Strapi project. - Add the following code to configure the StpDasboard plugin:1 ```ts 2 const { PLUGIN_STPDASHBOAD = false } = process.env; 3 4 const plugins = {}; 5 6 if (PLUGIN_STPDASHBOAD) { 7 plugins["strapi-plugin-dashboard"] = { enabled: true }; 8 } 9 export default () => (plugins); 10 ```
Explanation:
- The
PLUGIN_STPDASHBOAD
environment variable is used to determine whether the virtval plugin should be enabled. If this variable is set to true, the plugin will be enabled. - The plugins object is used to configure Strapi plugins.
- If
PLUGIN_STPDASHBOAD
is true, the virtval plugin is added to the plugins object with the enabled property set to true. - To enable the virtval plugin, you need to set the
PLUGIN_STPDASHBOAD
environment variable to true. This can be done in your.env
file or directly in your environment.1PLUGIN_STPDASHBOAD=true
- Once the environment variable is set and the server is restarted, the virtval plugin will be enabled and ready to use.
By following these steps, you can successfully install and configure the virtval plugin in your Strapi project, allowing you to take advantage of its features for rendering and managing values dynamically.
How It Works
One of the most powerful features of StpDasboard is its ability to represent multiple data points in a single chart using different visualization types such as Lines, Areas, Bars, and more. This flexibility allows users to create rich, informative dashboards that can display complex datasets in an intuitive and visually appealing way. Additionally, the plugin provides a user-friendly graphical interface for editing chart configurations, including the JSON structure, SQL queries, and chart titles. Let’s dive into how this works.
Graphical Interface for Chart Configuration
StpDasboard provides an intuitive graphical interface within the Strapi admin panel for editing and managing charts.
Editing Chart Configuration: The interface allows users to modify the JSON configuration directly or through form-based inputs. For example:
- Chart Title: Users can edit the label field to change the chart’s title.
- X-Axis and Y-Axis: Users can add or remove data series, change visualization types, and customize colors.
- Tooltips and Legends: Users can enable or disable tooltips and legends using toggle switches
Editing SQL Queries: For advanced users, the interface provides a code editor to modify the SQL query associated with the chart. This is particularly useful for:
- Adding filters or parameters.
- Joining multiple tables.
- Writing complex queries with subqueries or CTEs (Common Table Expressions).
Visualizing Data: The interface includes a preview panel where users can see the chart update in real-time as they make changes to the configuration or query. This ensures that the chart looks exactly as intended before saving.
Full-Screen Mode: Users can expand a chart to full-screen mode for a more detailed view. This is especially useful when presenting data to stakeholders or analyzing large datasets.
Deleting Charts: If a chart is no longer needed, users can easily delete it from the dashboard. A confirmation dialog ensures that accidental deletions are avoided.
Configuration
StpDasboard uses a JSON configuration file (config/charts.json
) to define the charts and dashboards. This file allows you to specify the chart types, data sources, and other customization options. Below is an example of how you can configure your charts using this file:
JSON Schema for Chart Configuration
The config/charts.json
file is a list of graphical objects, where each object represents a chart. Below is a generalized JSON Schema that describes the structure of each chart object:
1{
2 "type": "array",
3 "items": {
4 "type": "object",
5 "properties": {
6 "id": {
7 "type": "string",
8 "description": "A unique identifier for the chart."
9 },
10 "name": {
11 "type": "string",
12 "description": "The name of the chart."
13 },
14 "tooltip": {
15 "type": "boolean",
16 "description": "Enables or disables tooltips for the chart."
17 },
18 "legend": {
19 "type": "boolean",
20 "description": "Enables or disables the legend for the chart."
21 },
22 "xaxis": {
23 "type": "array",
24 "items": {
25 "type": "object",
26 "properties": {
27 "key": {
28 "type": "string",
29 "description": "The key for the X-axis data (e.g., time, category)."
30 }
31 },
32 "required": ["key"]
33 },
34 "description": "Defines the X-axis data for the chart."
35 },
36 "yaxis": {
37 "type": "array",
38 "items": {
39 "type": "object",
40 "properties": {
41 "type": {
42 "type": "string",
43 "enum": ["bar", "line", "area", "pie"],
44 "description": "The type of chart (e.g., Bar, Line, Area, Pie)."
45 },
46 "key": {
47 "type": "string",
48 "description": "The key for the Y-axis data."
49 },
50 "stroke": {
51 "type": "string",
52 "description": "The stroke color for the chart."
53 },
54 "fill": {
55 "type": "string",
56 "description": "The fill color for the chart."
57 },
58 "active": {
59 "type": "object",
60 "properties": {
61 "r": {
62 "type": "number",
63 "description": "The radius of active points (used in Line charts)."
64 }
65 }
66 }
67 },
68 "required": ["type", "key"]
69 },
70 "description": "Defines the Y-axis data and chart type."
71 },
72 "label": {
73 "type": "string",
74 "description": "The label for the chart."
75 },
76 "query": {
77 "type": "string",
78 "description": "The SQL query used to fetch data for the chart."
79 },
80 "vars": {
81 "type": "array",
82 "items": {
83 "type": "object",
84 "properties": {
85 "key": {
86 "type": "string",
87 "description": "The key for the variable."
88 },
89 "defaults": {
90 "type": "string",
91 "description": "The default value for the variable."
92 },
93 "component": {
94 "type": "string",
95 "description": "The UI component for the variable (e.g., select, input)."
96 },
97 "value": {
98 "type": "array",
99 "items": {
100 "type": "object",
101 "properties": {
102 "key": {
103 "type": "string",
104 "description": "The key for the variable option."
105 },
106 "value": {
107 "type": "string",
108 "description": "The value for the variable option."
109 }
110 }
111 }
112 }
113 },
114 "required": ["key", "defaults", "component"]
115 },
116 "description": "Variables used in the query (e.g., filters, parameters)."
117 }
118 },
119 "required": ["id", "xaxis", "yaxis", "label", "query"]
120 }
121}
Explanation of the Configuration:
- id: A unique identifier for each chart.
- name: The name of the chart.
- tooltip: Enables or disables tooltips for the chart.
- legend: Enables or disables the legend for the chart.
- xaxis: Defines the X-axis data, typically a time series or category.
- yaxis: Defines the Y-axis data, including the type of chart (e.g., Bar, Line, Area) and the data key.
- label: The label for the chart.
- query: The SQL query used to fetch the data.
- vars: Variables that can be used in the query, such as filters or parameters.
Simplified Example
Here’s a simplified example of a config/charts.json
file with a single chart:
1[
2 {
3 "id": "123456789",
4 "name": "sales",
5 "tooltip": true,
6 "legend": true,
7 "xaxis": [
8 {
9 "key": "month"
10 }
11 ],
12 "yaxis": [
13 {
14 "type": "bar",
15 "key": "total_sales",
16 "stroke": "#8884d8",
17 "fill": "#8884d8"
18 }
19 ],
20 "label": "Monthly Sales",
21 "query": "SELECT TO_CHAR(order_date, 'YYYY-MM') AS month, SUM(sales) AS total_sales FROM orders GROUP BY month ORDER BY month;",
22 "vars": []
23 }
24]
The SQL query could be as complex as necessary:
1SELECT TO_CHAR(order_date, 'YYYY-MM') AS month,
2 SUM(sales) AS total_sales,
3 SUM(profits) AS total_profits
4FROM orders
5GROUP BY month
6ORDER BY month;
Explanation:
- This configuration defines a single chart that displays monthly sales data.
- The X-axis represents the month, and the Y-axis represents the total_sales.
- The chart type is a Bar chart.
- The SQL query is simple: it groups sales data by month and calculates the total sales for each month.
Complex Query Example
For more advanced use cases, you can use complex SQL queries with joins, subqueries, and variables. Here’s an example based on the original configuration:
1[
2 {
3 "id": "1735854711217",
4 "tooltip": true,
5 "legend": true,
6 "xaxis": [
7 {
8 "key": "month"
9 }
10 ],
11 "yaxis": [
12 {
13 "type": "line",
14 "key": "shipping_count",
15 "stroke": "#8884d8"
16 },
17 {
18 "type": "line",
19 "key": "weight_total",
20 "stroke": "#d811d8"
21 }
22 ],
23 "label": "Shipping History",
24 "query": "WITH package_data AS (SELECT s.id AS shipping_id, COALESCE(SUM(p.weight), 0) AS weight_total FROM public.packages AS p INNER JOIN public.packages_shipping_lnk AS ps ON ps.package_id = p.id INNER JOIN public.shippings AS s ON s.id = ps.shipping_id WHERE EXTRACT(YEAR FROM s.published_at) = :year GROUP BY s.id) SELECT TO_CHAR(DATE_TRUNC('month', s.published_at), 'YYYY-MM') AS month, COUNT(DISTINCT s.id) AS shipping_count, COALESCE(SUM(pd.weight_total), 0) AS weight_total FROM public.shippings AS s LEFT JOIN package_data AS pd ON pd.shipping_id = s.id WHERE EXTRACT(YEAR FROM s.published_at) = :year GROUP BY DATE_TRUNC('month', s.published_at) ORDER BY DATE_TRUNC('month', s.published_at);",
25 "vars": [
26 {
27 "key": "year",
28 "defaults": "2024",
29 "component": "select",
30 "value": [
31 {
32 "key": "2023",
33 "value": "2023"
34 },
35 {
36 "key": "2024",
37 "value": "2024"
38 }
39 ]
40 }
41 ]
42 }
43]
The SQL query could be as complex as necessary:
1WITH monthly_data AS (
2 SELECT
3 DATE_TRUNC('month', order_date) AS month,
4 SUM(sales) AS total_sales,
5 SUM(profits) AS total_profits,
6 SUM(costs) AS total_costs
7 FROM orders
8 WHERE EXTRACT(YEAR FROM order_date) = :year
9 GROUP BY DATE_TRUNC('month', order_date)
10)
11SELECT
12 TO_CHAR(month, 'YYYY-MM') AS month,
13 total_sales,
14 total_profits,
15 total_costs
16FROM monthly_data
17ORDER BY month;
Explanation:
- This chart displays shipping history, including the number of shipments (
shipping_count
) and total weight (weight_total) per month. - The query uses a Common Table Expression (CTE) to calculate the total weight of packages for each shipment.
- The vars section allows the user to select a year (
2023
or2024
) to filter the data.
Representing Multiple Data Points in a Single Chart
In StpDasboard, a single chart can display multiple datasets, each represented by a different visualization type. This is achieved through the yaxis property in the JSON configuration. Each entry in the yaxis array defines a dataset and its corresponding visualization type. For example:
1{
2 // ...
3 "yaxis": [
4 {
5 "type": "line",
6 "key": "total_sales",
7 "stroke": "#8884d8"
8 },
9 {
10 "type": "area",
11 "key": "total_profits",
12 "stroke": "#82ca9d",
13 "fill": "#82ca9d"
14 },
15 {
16 "type": "bar",
17 "key": "total_costs",
18 "stroke": "#ff8042",
19 "fill": "#ff8042"
20 }
21 ]
22 // ...
23}
Explanation:
- type: Specifies the visualization type (e.g.,
line
,area
,bar
). - key: The key in the dataset that corresponds to this data series.
- stroke: The color of the line or border for the visualization.
- fill: The fill color for visualizations like Area charts.
In this example:
- total_sales is represented as a Line.
- total_profits is represented as an Area.
- total_costs is represented as a Bar.
With the generalized JSON Schema and examples provided, you can now better understand how to configure and use StpDasboard for your Strapi projects. Whether you need a simple chart or a complex dashboard with advanced queries, StpDasboard offers the flexibility and power to meet your data visualization needs. Start building your dynamic dashboards today!
Similar Plugin
- VirtVal Plugin: Strapi plugin to add a field with a virtual or external value to an existing Content-Type, find it at Strapi Market.
Conclusion
StpDasboard is a powerful addition to the Strapi ecosystem, providing developers and content managers with the tools they need to create dynamic, customizable dashboards. With support for multiple chart types, real-time data, and seamless integration with Strapi, StpDasboard is the ultimate solution for data visualization in your Strapi projects.
Whether you're building a simple dashboard for internal use or a complex data visualization for your users, StpDasboard makes it easy to bring your data to life. Start using StpDasboard today and take your Strapi experience to the next level!
Install now
npm install strapi-plugin-dashboard
Create your own plugin
Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.