Create ChartLines

Example
Prompt
Code

Tutorial

Here is a step-by-step tutorial on how to complete the function fn:

Define the initial SQL query: The SQL query should select the necessary data from the database. In this case, we want to count the number of users created in the last 30 days and group them by month and year.

ts
let sql = `SELECT date_format(creationDate, "%m/%Y") as label, count(1) as conteo from users WHERE creationDate >= NOW() - interval 30 day orderBy creationDate ASC`;

Execute the SQL query: Use the query method provided in req to execute the SQL query and get the results.

ts
let results = await req.query(sql);

Display the chart: Use the chartLine method provided in req to send the formatted data as a line chart response.

ts
return res.chartLine(data);

Final Result

With these steps, you have completed the fn function. Now, when this function is called, it will return a line chart showing the number of users created per month in the last 30 days. Make sure to adjust the code according to your application's specifications and structure.

ts
const fn = async function (req: Request, res: Response) { let sql = `SELECT date_format(creationDate, "%m/%Y") as label, count(1) as conteo from users WHERE creationDate >= NOW() - interval 30 day orderBy creationDate ASC`; let results = await req.query(sql); return res.chartLine(results); };
How to start
Click to go
How to create Tables
Click to go
On this page

Create ChartLines

Tutorial

Final Result

View this page on
GitHub

Do you have specific enterprise needs? Contact our sales team.

get enterprise

Make your business efficient in seconds.

Create dashboards and backoffices in seconds
Start now