How Data rendering to jsreport?



  • I would like to know how Data come to jsreport . I saw the script file and understand
    that how data displayed in the jsreport , however I don't know where actually data is rendering from. I need to change the country name like 'France ' into China . I tried to change it but after changed I lost graph's visual data because of condition in that beforeRender function. So please, anyone help me .

     function beforeRender(req, res, done) {
    req.data.country = req.data.country || 'France';
    req.data.orders = [];
       getData(req, function (err) {
        if (err) {
            return done(err);
        }
        
        req.data.ordersCount = req.data.orders.length;
        
        req.data.customers.forEach(function (c) {
            c.ordersCount = req.data.orders.filter(function (o) {
                return o.CustomerID === c.CustomerID;
            }).length;
        });
        
        
        var ordersByQuarter = {};
        req.data.orders.forEach(function (o) {
            o.OrderDate = new Date(o.OrderDate);
           
            var key = o.OrderDate.getFullYear() + '/' + (o.OrderDate.getMonth() + 1);
            ordersByQuarter[key] = ordersByQuarter[key] || { value: 0, orderDate: o.OrderDate };
            ordersByQuarter[key].value++;
        });
        
        req.data.accumulatedOrders = ordersByQuarter
        
        done();
    })}
    

    After changed country name
    0_1497538264314_upload-611294b7-cf5d-47bd-b3b8-543c4922541f


  • administrators

    Data is sent to jsreport in two ways:

    • you can pass it in HTTP's request payload (data property) when rendering reports with the jsreport HTTP API
    • when using jsreport-studio you can create data files and use it with your templates in order to populate req.data with some sample data while you are developing the report

    but it seems like your example is not using any data file and it is actually fetching data from elsewhere, take a look in getData function, i can't see the source of your getData function so i assume that it is fetching data from another server and use it to fill req.data.

    also to provide help to you more quickly try to upload a fully working example in the playground



  • Thank you so much !!


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.