Node js error importing module

Asked

Viewed 78 times

0

Good afternoon to everyone, I am trying to organize my project, I prescribe to work with Ode, I have a function that creates a chart, I separated it into a separate file and exported this function so that I can use in my view. But he makes the following mistake:

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

File view.js

require('./modules/createGraphic') 

File createGraphic

var createGraph =  function createGraph(matrix, title, classHtml) {
    var dimensao = []
    var measure = []
    dimensao = matrix.map((item) => { return item[0].qText })
    measure = matrix.map((item) => { return item[1].qText })

    var ctx = document.getElementsByClassName(classHtml)
    var chartGrap = new Chart(ctx, {
      type: 'line',
      layout: {
        padding: {
          left: 0,
          right: 0,
          top: 0,
          bottom: 0
        }
      },
      data: {
        labels: dimensao,
        datasets: [{
          label: 'taxa',
          data: measure,
          borderWidth: 5,
          borderColor: ['rgba(75, 192, 192, 1)', 'rgba(192, 0, 0, 1)'],
          backgroundColor: ['rgba(75, 192, 192, 0.2)', 'rgba(192, 0, 0, 0.2)'],
          pointBackgroundColor:'#800b0b',
          lineCap:'round'
        }]
      },
      options: {
        title: {
          display: true,
          text: title
        }
      }
    })
  }
  module.exports = createGraph

The function is working. I did the tests and it worked out what catching you is this file.

  • Could you post the code snippet that is using this reference? You are using this function directly within a view?

  • require('./modules/createGraphic') require(["js/Qlik"], Function (Qlik) {
 var app = qlik.openApp('Recurso Humanos.qvf', config);
 app.getObject('filtro', 'zSmqYhK')
 app.getObject('kpi1', 'dRApjU')
 app.getObject('aoLongo', 'ebnCpu')
 app.getObject('kpi2', 'HuKkTX')
 app.getObject('kpi3', 'eJKBPu')
 app.getObject('kpi4', 'gbwRegu') app.getObject('barraSelecao', 'Currentselections')}) this is the snippet of the code q would be in the view, at the moment I do not want to show anything on the screen I would just like to get the modules to perform these functions of destintos files.

  • It’s still not very clear to me, but I suggest migrating this code snippet from the view to a controller. Within the controller perform the necessary processing and then pass the information (model) to view via the command: res.render('minhaView', { dados: 123 });. If you still need to do some processing inside the view take a look at this link: https://medium.com/@Marcelo.vismari/nodejs-express-ejs-como-usar-funcoes-durante-renderizacao-f51122e1eaca

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.