javascript - Display image based on response from getJSON data -


i new web development , trying figure out how display image based on response getjson. data being received rest api. data stored in 2 arrays, humid , date. humid contains humidity string. humid array converted integer array- humid_final. wanted know how display image on screen based on particular value in humid_final array.

if latest entry in humid_final array= 50 display image a. else display image b. (where image a,b static images stored locally).

$(function updat() {    var url = "https://xpm4zyor39.execute-api.us-west-2.amazonaws.com/prod/entries";    var humid = [],      date = [],      humid_final = []      $.getjson(url, function (json) {        $(json['items']).each(function(i, data) {        //store indicator name                // fill date array        humid.push(data.humidity);        // fill string data array         date.push(data.date);      });        console.log(date);      // query send string need convert numbers      (var = 0; < humid.length; i++) {        if (humid[i] != null) {          humid_final.push(parsefloat(humid[i]))        } else {         humid_final.push(null)        };      }        var chart = new highcharts.chart({        chart: {          type: 'spline',          renderto: 'container'        },        title: {          text: 'indicatorname'        },        tooltip: {          valuedecimals: 2,          pointformat: '<span style="color:{point.color}">\u25cf</span> {series.name}: <b>{point.y}%</b><br/>'        },        plotoptions: {          series: {            marker: {              enabled: false            }          }        },        subtitle: {          text: 'source: world bank data'        },        xaxis: {          categories: date //.reverse() have min year on left         },        series: [{          name: 'humidity',          data: humid_final //        }]      });      }); //getjson method    settimeout(updat, 3000);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>  <script src="https://code.highcharts.com/highcharts.js"></script>  <script src="https://code.highcharts.com/modules/exporting.js"></script>  <script src= "opendataapi.js"></script>  <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

you're there. give image tag in html id , make point standard image imageb <img id="changingimage" src="./images/imageb.png" />

then let's try translate ...

if latest entry in humid_final array= 50 display image a. else display image b. 

into javascript:

if (humid_final[humid_final.length-1] == 50) {     document.getelementbyid('changingimage').src="./images/imagea.png"; } 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -