Demonstration of sales reporting with graph using integrated results files from a database
🧑💻 See the sales report preparation note to configure your database
SELECT
channel,
DATE_FORMAT(sale_date, '%Y-%m') AS month,
SUM(price) AS total_sales_amount,
COUNT(*) AS total_sales
FROM
Sales
GROUP BY
channel, month
ORDER BY month ASC;
// Get data from SQL database and save results into a JSON file
const sql = loadBlock("orders");
const json = await getSQL(sql, "127.0.0.1", 3306, "mysql", "user", "password", "database");
_fs.writeFileSync(__dirname + "/orders-channel.json", JSON.stringify(json));
print("Done");
// Loads and integrates the JSON file with deployment
// This block will be displayed in the report
const json = require("./orders-channel.json");
barChart({
horizontal:true,
series: toSeries({data:json, x:"month", y:"total_sales_amount", category:"channel"}),
});