No variable reading



  • Hello! I'm trying to make a schedule updated from the OBD system. I've done almost everything, I'm up at one point. When trying to pass the variable data (data_result), nothing happens. If you put it in instead of variable, it works. What's my mistake?

    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
    var dataChart = google.visualization.arrayToDataTable([
    ['1470139847',1.11,1.11,1.11,1.11],
    ['1470139847',1.11,1.11,1.11,1.11],
    ['1470139847',1.11,1.11,1.11,1.11]
      // Treat first row as data as well.
    ], true);
    

    var options = {
    legend:'none'
    };

    var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div'));
    var value_arr = new Array();
    var inv_date = '';
    var data_result = '';

    chart.draw(dataChart, options);
    updateChart(dataChart, chart, options, value_arr, inv_date);
    }
    function updateChart(dataChart, chart, options, value_arr, inv_date) {
    var option = $('#option').val();

    $.ajax({
        type: "POST",
        url:'/ajax.php',
        data:({
            option: option
        }),
        success: function(data) {
            var rateVal = data.split(';');
            $('#rateVal').text(data);
            value_arr.push(rateVal[0]);
            inv_date = rateVal[1];
        }
    });
    if (value_arr.length == 4) {
        data_result = "'" + inv_date + "'," + value_arr[0] + ',' + value_arr[1] + ',' + value_arr[2] + ',' + value_arr[3];
        dataChart.addRow([data_result]);
        chart.draw(dataChart, options);
        var value_arr = new Array();
    }
    

    setTimeout(function(){updateChart(dataChart, chart, options, value_arr, inv_date)}, 1000);
    }

    </script>
    <div id="chart_div" style="width: 900px; height: 300px;"></div>


    Data required to be transferred to Float for the schedule



  • The mistake is how you make data for transmission to addRow.

    When you do

    data_result = "'" + inv_date + "'," + value_arr[0] + ',' + value_arr[1] + ',' + value_arr[2] + ',' + value_arr[3];
    dataChart.addRow([data_result]);
    

    In a function addRow comes this.

    addRow(["'foo',bar,foo2,bar2"])
    

    I mean, a mass with one element is a line. Probably not what you expected.

    You need to do something like that:

    data_result  = [inv_date,value_arr[0],value_arr[1],value_arr[2],value_arr[3]];
    dataChart.addRow(data_result);
    

    or more

    dataChart.addRow([inv_date,value_arr[0],value_arr[1],value_arr[2],value_arr[3]]);
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2