javascript - Update Line Chart d3.js -


i creating line chart using d3.js , svg, populated data returned adobe analytics real-time api.

i able create line chart initially, able loop through api call , call new data every 5 seconds. can update linedata object new data.

i can't line chart update new data. below code update function. please advise have gone wrong , changes need make line chart update new data.

    //update data loop     function updatedata() {         //add time dates         if(inputstartminute > 55) {             if(inputstarthour == 23) {                 inputstarthour = 0;             } else {                 inputstarthour = inputstarthour + 1;             }             inputstartminute = inputstartminute - 60 + 5;         } else {             if(inputstarthour == 23) {                 inputstarthour = 0;             } else {                 inputstarthour = inputstarthour + 1;             }             inputstartminute = inputstartminute - 60 + 5;                        };         if(inputendminute > 55) {             if(inputendhour == 23) {                 inputendhour = 0;             } else {                 inputendhour = inputendhour + 1;             }             inputendminute = inputendminute - 60 + 5;         } else {             if(inputendhour == 23) {                 inputendhour = 0;             } else {                 inputendhour = inputendhour + 1;             }             inputendminute = inputendminute - 60 + 5;                        };          //create new dates         startdate = new date(inputyear,inputmonth,inputday, inputstarthour, inputstartminute)         console.log(startdate);         enddate = new date(inputyear,inputmonth,inputday, inputendhour, inputendminute)         console.log(enddate);          //convert dates adobe format yyyy-mm-dd hh:mm:ss         var startyear = startdate.getfullyear();         if(startdate.getmonth() < 10) {             var startmonth = '0' + startdate.getmonth();         } else {             var startmonth = 1 + startdate.getmonth();         }         if (startdate.getdate() < 10) {             var startday = startdate.getdate();         } else {             var startday = startdate.getdate();         }         if(startdate.gethours() < 10) {             var starthour = '0'+startdate.gethours();         } else {             var starthour = startdate.gethours();         }         if(startdate.getminutes() < 10) {             var startminute = '0'+startdate.getminutes();         } else {             var startminute = startdate.getminutes();         }         var starttime = starthour+':'+startminute;         startdate = startyear+'-'+startmonth+'-'+startday+' '+starttime;         console.log(startdate);          var endyear = enddate.getfullyear();         if(enddate.getmonth() < 10) {             endmonth = '0' + enddate.getmonth();         } else {             var endmonth = 1 + enddate.getmonth();         }         if (enddate.getdate() < 10) {             var endday = enddate.getdate();         } else {             var endday = enddate.getdate();         }         if(enddate.gethours() < 10) {             var endhour = '0'+enddate.gethours();         } else {             var endhour = enddate.gethours();         }         if(enddate.getminutes() < 10) {             var endminute = '0'+enddate.getminutes();         } else {             var endminute = enddate.getminutes();         }         var endtime = endhour+':'+endminute;         enddate = endyear+'-'+endmonth+'-'+endday+' '+endtime;         console.log(enddate);          //set dates api request         var datefrom = startdate;         console.log(datefrom);         var dateto = enddate;         console.log(dateto);          //set  parameters , call report         params = {'reportdescription':{'reportsuiteid':'whitpreminnprod','datefrom':datefrom,'dateto':dateto,'dategranularity':'minute:1','metrics':[{'id':'pageviews'}],'source':'realtime',}};         var realtimepageviews = '';         marketingcloud.makerequest(username, secret, method, params, endpoint, function(response) {             realtimepageviews = json.parse(response.responsetext);             console.log(realtimepageviews);              //assign data points linedata object             linedata = [{                 x: realtimepageviews.report.data[0].minute,                 y: parseint(realtimepageviews.report.data[0].counts[0])             }, {                 x: realtimepageviews.report.data[1].minute,                 y: parseint(realtimepageviews.report.data[1].counts[0])             }, {                 x: realtimepageviews.report.data[2].minute,                 y: parseint(realtimepageviews.report.data[2].counts[0])             }, {                 x: realtimepageviews.report.data[3].minute,                 y: parseint(realtimepageviews.report.data[3].counts[0])             }, {                 x: realtimepageviews.report.data[4].minute,                 y: parseint(realtimepageviews.report.data[4].counts[0])             }, {                 x: realtimepageviews.report.data[5].minute,                 y: parseint(realtimepageviews.report.data[5].counts[0])             }, {                 x: realtimepageviews.report.data[6].minute,                 y: parseint(realtimepageviews.report.data[6].counts[0])             }, {                 x: realtimepageviews.report.data[7].minute,                 y: parseint(realtimepageviews.report.data[7].counts[0])             }, {                 x: realtimepageviews.report.data[8].minute,                 y: parseint(realtimepageviews.report.data[8].counts[0])             }, {                 x: realtimepageviews.report.data[9].minute,                 y: parseint(realtimepageviews.report.data[9].counts[0])             }, {                 x: realtimepageviews.report.data[10].minute,                 y: parseint(realtimepageviews.report.data[10].counts[0])             }, {                 x: realtimepageviews.report.data[11].minute,                 y: parseint(realtimepageviews.report.data[11].counts[0])             }];              //use data points define scale             xscale = d3.scalelinear().range([margins.left, width-margins.right]).domain([d3.min(linedata, function(d) {                 return d.x;             }), d3.max(linedata, function(d) {                 return d.x;             })]),             yscale = d3.scalelinear().range([height - margins.top, margins.bottom]).domain([d3.min(linedata, function(d) {                 return d.y;             }), d3.max(linedata, function(d) {                 return d.y;             })]),              //define linefunc within function             linefunc = d3.line()                 .x(function(d) {                 return xscale(d.x);                 })                 .y(function(d) {                 return yscale(d.y);                 })                 .curve(d3.curvebasis);              //select visualisation , modify line             vis = d3.select('#visualisation').transition();              vis.select('.line')                 .duration(750)                 .attr('d', linefunc(linedata));             vis.select('.x.axis')                 .duration(750)                 .call(xaxis);             vis.select('.y.axis')                 .duration(750)                 .call(yaxis);         });     } 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -