Skip to content

Latest commit

 

History

History
62 lines (44 loc) · 1.95 KB

show-doughnut.mdx

File metadata and controls

62 lines (44 loc) · 1.95 KB

Create Doughnut

<Tabs tabs={["Example", "Prompt", "Code"]}>

Show me a Doughnut with the count of customers active and inactive.
```ts const fn = async function (req: Request, res: Response) { let sql = `SELECT if(active = 1, "Active", "Inactive") as label count(1) quantity FROM users GROUP BY active`; let results = await req.query(sql); return res.chartDoughnut(results); }; ``` ---

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.

let sql = `SELECT if(active = 1, "Active",  "Inactive") as label count(1) quantity   FROM users GROUP BY active`;

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

let results = await req.query(sql);

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

return res.chartDoughnut(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.

const fn = async function (req: Request, res: Response) {
  let sql = `SELECT if(active = 1, "Active",  "Inactive") as label count(1) quantity   FROM users GROUP BY active`;
  let results = await req.query(sql);
  return res.chartDoughnut(results);
};