values for the Y-Axis. values is an array, each item is a line of the chart.
A line is a key/values object with key for the line's name.
How to build the expected JSON for multiple-line chart
The following example uses a raw SQL query but it could be replaced by a Sequelize / Mongoose query.
const_=require('lodash');constmoment=require('moment');constexpress=require('express');constrouter=express.Router();constLiana=require('forest-express-sequelize');constmodels=require('../models');router.post('/stats/multilines', (request, response, next) => {/* Here the query with the 2 lines: orders & new_users */constquery=` select 'orders' as "key", week_day, nb from week_orders union select 'new_users' as "key", week_day, nb from week_new_users order by week_day, "key" `;returnmodels.sequelize.query(query).then((results) => {constrecords= results[0];/* Expected Result: labels (X-axis), [values] (Y-axis): one array per line */let resultsFormated = { labels: [], values: [] };/* Get the X-axis labels => Week numbers */constweeks=_.uniq(records.map((r) =>r.week_day ));resultsFormated.labels =weeks.map((m) =>moment(m).format('[W]w-YYYY'));/* Get the Y-axis values */var keys =_.uniq(records.map((r) =>r.key));/* Build one array per key / line */keys.forEach((key) => {var current =_.filter(records, { key });constvalues=current.map((c) =>c.nb);resultsFormated.values.push({ key: key, values: values }); });/* Use Liana.StatSerializer to Jsonify the result */var json =newLiana.StatSerializer({ value: resultsFormated }).perform();response.send(json); });});