Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow successive ajax requests to reuse the same graph instance

  • Loading branch information...
commit 9bc06660d0e3e8a0dcd34711c6a9ce282e8f1830 1 parent feec7e2
@dchester dchester authored
View
14 examples/data/data2.json
@@ -0,0 +1,14 @@
+[
+ {
+ "color": "blue",
+ "name": "New York",
+ "data": [ { "x": 0, "y": 50 }, { "x": 1, "y": 32 }, { "x": 2, "y": 38 }, { "x": 3, "y": 30 }, { "x": 4, "y": 32 } ]
+ }, {
+ "name": "London",
+ "data": [ { "x": 0, "y": 19 }, { "x": 1, "y": 76 }, { "x": 2, "y": 28 }, { "x": 3, "y": 20 }, { "x": 4, "y": 14 } ]
+ }, {
+ "name": "Tokyo",
+ "data": [ { "x": 0, "y": 8 }, { "x": 1, "y": 12 }, { "x": 2, "y": 14 }, { "x": 3, "y": 11 }, { "x": 4, "y": 28 } ]
+ }
+]
+
View
50 examples/refresh.html
@@ -0,0 +1,50 @@
+<!doctype html>
+<head>
+
+ <link type="text/css" rel="stylesheet" href="../rickshaw.css">
+
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
+
+ <script src="../vendor/d3.v2.js"></script>
+ <script src="../rickshaw.js"></script>
+</head>
+<body>
+
+<div id="chart_container">
+ <div id="chart"></div>
+ <button id="refresh">refresh</button>
+</div>
+
+<script>
+
+var dataURLs = ['data/data.json', 'data/data2.json'];
+
+var ajaxGraph = new Rickshaw.Graph.Ajax( {
+
+ element: document.getElementById("chart"),
+ width: 400,
+ height: 200,
+ renderer: 'line',
+ dataURL: 'data/data.json',
+ series: [
+ {
+ name: 'New York',
+ color: '#c05020',
+ }, {
+ name: 'London',
+ color: '#30c020',
+ }, {
+ name: 'Tokyo',
+ color: '#6060c0'
+ }
+ ]
+} );
+
+document.querySelector('#refresh').addEventListener('click', function() {
+ ajaxGraph.dataURL = ajaxGraph.dataURL === dataURLs[0] ? dataURLs[1] : dataURLs[0];
+ ajaxGraph.request();
+});
+
+</script>
+
+</body>
View
4 src/js/Rickshaw.Graph.Ajax.js
@@ -36,7 +36,7 @@ Rickshaw.Graph.Ajax = Rickshaw.Class.create( {
data = this.onData(data);
this.args.series = this._splice({ data: data, series: this.args.series });
- this.graph = new Rickshaw.Graph(this.args);
+ this.graph = this.graph || new Rickshaw.Graph(this.args);
this.graph.render();
this.onComplete(this);
@@ -62,7 +62,7 @@ Rickshaw.Graph.Ajax = Rickshaw.Class.create( {
if (seriesKey == dataKey) {
var properties = ['color', 'name', 'data'];
properties.forEach( function(p) {
- s[p] = s[p] || d[p];
+ if (d[p]) s[p] = d[p];
} );
}
} );
Please sign in to comment.
Something went wrong with that request. Please try again.