Variable in EJS

1

Good morning everyone!

So, come on: I'm trying to use Plotly to generate a bar chart, and it accepts variables. I have a connection in NODE.JS with a database, and NODE.JS in thesis (After a console.log in the route) is passing to the view which is the JSON object with all the values of the database that I will use. What I would like to know is ... How can I use a variable in the view to store only the numeric values that will be used in the chart (No X)? Even because, if I have a value or 20 numeric values, the corresponding rows should be generated ... Should I have this inside a for? The same logic I will use with the name (No Y) ... Route:

    app.get('/barras', function(req,res){
    console.log('Database connection online');
    connection.query('select progresso from barra', function(error,result){
        barras = result;
        console.log(barras);
        res.render('admin/barras',barras);
    });
});

View:

    <!DOCTYPE html>
<html>
<head>
  <!-- Plotly.js -->
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script></head><body><divid="myDiv" style="width: 480px; height: 400px;"><!-- Plotly chart will be drawn inside this DIV --></div>
  <script>
  var barras = barras;
  console.log(barras);
  var data = [{
      type: 'bar',
      x: [17,20,84],
      y: ['teste1', 'teste2', 'teste3'],
      orientation: 'h'
  }];

Plotly.newPlot('myDiv', data);
  </script>
</body>
</html>

The JSON that is sent is [RowDataPacket {progress: 11}, RowDataPacket {progress: 10}, RowDataPacket {progress: 20}]

    
asked by anonymous 11.09.2018 / 14:24

0 answers