Why Document.getElementById('value'). value does not work in Rgraph?

Asked

Viewed 404 times

0

// Classe para chamar o Json.
function json() {
  var qtd;
  var retorno;

  // Resgatar valores.
  json.prototype.resgatarValores = function() {
    $('#resultado').html('Carregando dados...');

    // Estrutura de resultado.
    $.getJSON('/webpro/webadm/lncidjson', function(data) {
      this.qtd = data.usuarios.length - 1;
      this.valore = '';
      this.label = '';

      for (i = 0; i < this.qtd; i++) {
        if (i == (this.qtd - 1)) {
          this.valore += data.usuarios[i].valor;
          this.label += data.usuarios[i].descr;
        } else {
          this.valore += data.usuarios[i].valor + ',';
          this.label += data.usuarios[i].descr + ',';
        }
      }

      $('#valor').html(this.valore);
      $('#label').html(this.label);
    });

  }

}

// Objeto.
var obj = new json();
obj.resgatarValores();

I want to take the values of the Divs and play in the variaves "date" and "Labels" more when I order to take the value of the div does not appear anything. I have shown with Alert() plus the box is empty

        $(document).ready(function ()
        {

            var data     = [document.getElementById('valor').value];
            var tooltips = [];
            //[2.59,2.60,2.40,2.67,1.78];
			
            // Create the tooltips
            for (var i=0; i<data.length; i+=1) {
                tooltips[i] = '1 USD = ' + String(data[i] + ' Reais')
            }

            var line = new RGraph.Line({
                id: 'cvs',
                data: data,
                options: {
                    tooltips: {
                        self: tooltips,
                        highlight: false
                    },
                    colors: ['#058DC7'],
                    filled: true,
                    fillstyle: 'rgba(229,243,249,0.5)',
                    tickmarks: 'filledcircle',
                    background: {
                        grid: {
                            vlines: false,
                            border: false,
                            autofit: {
                                numhlines: 10
                            }
                        }
                    },
                    shadow: false,
                    linewidth: 3,
                    gutter: {
                        left: 50,
                        right: 20
                    },
                    numxticks: 0,
                    ylabels: {
                        count: 5
                    },
                    axis: {
                        color: '#aaa'
                    },
                    text: {
                        color: '#aaa'
                    },
                    labels: ['21/01','22/01','23/01','24/01','25/01']
                }
            })
            
            RGraph.ISOLD ? line.draw() : line.trace2();
            
        })
<!DOCTYPE html >

<html>
<head>
    <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />
    
    <script src="/sistema/jquery/plugins/RGraph/libraries/RGraph.common.core.js" ></script>
    <script src="/sistema/jquery/plugins/RGraph/libraries/RGraph.common.dynamic.js" ></script>
    <script src="/sistema/jquery/plugins/RGraph/libraries/RGraph.common.tooltips.js" ></script>
    <script src="/sistema/jquery/plugins/RGraph/libraries/RGraph.line.js" ></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
	<script type="text/javascript" src="http://www.google.com/jsapi"></script>
	<script type="text/javascript">
		google.load("jquery", "1.3.2", {uncompressed:true});
	</script>
	<script type="text/javascript" src="json.class.js"></script>

    <!--[if lt IE 9]><script src="../excanvas/excanvas.js"></script><![endif]-->
    
    <p style="margin-left:50em;"><title>Cotação USD x BRL</title></p>
    
    <meta name="robots" content="noindex,nofollow" />
    <meta name="Descrição" content="Cotação do Dolar de Acordo com o Real" />
     
</head>
<body>

    <h2></h2>

    <canvas id="cvs" width="900" height="300">[No canvas support]</canvas>
    
  
	<div id="valor"></div>
	<div id="label"></div>
  
	
</body>
</html>

  • This is the fourth question on this subject. We want to help but you have to show all the code you have and a live example of the problem. Otherwise it becomes difficult to help and accumulate questions that do not lead to the answer/solution.

  • @Sergio all the code I have is above

  • And this Javascript with the Class to call Json is in a separate file?

  • <div> has not value, has innerHTML.

  • @Sergio yes are 2 files I have and posted.

  • @bfavaretto I’ve tried to put with innerHTML more also not showed the data.

  • Friend your variable data is populated before the function resgatarValores end your request. Think of me as a web request. It can last a variable time while document.getElementById('valor').innerHTML must be executed well before the request response does not return any data. Try to execute the code within the $(document).ready(function () after receiving your JSON and let us know if there was a difference.

Show 2 more comments
No answers

Browser other questions tagged

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