javascript - Real time data graphing on a line chart with the help of rickshaw and d3.js -


i want make real time dynamic graph on line chart of rickshaw , d3.js, gives fresh data without refreshing whole page. in following example build graph on random data. in problem data not fresh refreshing of browser fresh data please see link. ajax request using reference here please see it

i copied whole code below. want make graph movable, real time update flot, don't want use flot, rickshaw.

    <!doctype> <head>         <title>rickshaw greaph examples</title>         <meta http-equiv="content-type" content="text/html; charset=utf-8">     <link type="text/css" rel="stylesheet" href="../src/css/graph.css">         <link type="text/css" rel="stylesheet" href="../src/css/legend.css">         <link type="text/css" rel="stylesheet" href="../src/css/detail.css">     <link type="text/css" rel="stylesheet" href="css/lines.css">      <script src="../vendor/d3.v3.js"></script>      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>      <script src="../rickshaw.js"></script> </head> <body>  <div id="chart_container" style="margin:0px auto;width:660px;">     <div id="chart"></div>         <div id="legend_container">             <div id="smoother" title="smoothing"></div>             <div id="legend"></div>         </div>         <div id="slider"></div> </div>  <script>        // set our data series 50 random data points         var seriesdata = [ [], [], [] ];         var random = new rickshaw.fixtures.randomdata(150);          (var = 0; < 150; i++) {             random.adddata(seriesdata);         }  var ajaxgraph = new rickshaw.graph.ajax( {      element: document.getelementbyid("chart"),     width: 400,     height: 200,     renderer: 'line',     series: [         {             name: 'new york',                         data: seriesdata[0],             color: '#c05020',         }, {             name: 'london',                         data: seriesdata[0],             color: '#30c020',         }, {             name: 'tokyo',                         data: seriesdata[0],             color: '#6060c0'         }     ] } ); ajaxgraph.render();  var hoverdetail = new rickshaw.graph.hoverdetail( {             graph: graph         } );          var legend = new rickshaw.graph.legend( {             graph: graph,             element: document.getelementbyid('legend')          } );          var shelving = new rickshaw.graph.behavior.series.toggle( {             graph: graph,             legend: legend         } );           var axes = new rickshaw.graph.axis.time( {             graph: graph         } );         axes.render(); </script>  </body> 

to realtime data in d3 chart, need either implement polling script on json url or utilize websockets real-time communication.

a polling script query json url every x seconds, , execute d3 add / update / delete pattern appropriate.

with websockets, can maintain persistant connection api , server sends messages connected clients when data updated. again call d3 add / update / delete pattern.

so example web sockets:

https://stackoverflow.com/a/13694422/2490989

polling example:

http://www.devixgroup.com/blog/2015/01/using-ajax-polling-with-d3-js-eventdrops-project/


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -