Note that there are some explanatory texts on larger screens.

plurals
  1. POSame data structure returned from javascript and python behaves differently in d3.js
    primarykey
    data
    text
    <p>When I am using this data structure from a javascript source file:</p> <pre><code>var data = [{'x': 100, 'y': '65'}, {'x': 122, 'y': '57'}, {'x': 144, 'y': '101'}, {'x': 166, 'y': '87'}, {'x': 188, 'y': '8'}, {'x': 210, 'y': '180'}, {'x': 232, 'y': '132'}, {'x': 257, 'y': '190'}, {'x': 276, 'y': '210'}, {'x': 298, 'y': '150'}] </code></pre> <p>and <code>alert</code> the data in my main file it shows:</p> <pre><code>[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object] </code></pre> <p>also it works fine with :</p> <pre><code>alert(d3.max(data,function(d) { return d.count;})) </code></pre> <p>But when I using a python as a source file and returns this :</p> <pre><code> data = [{'x': 100, 'y': '65'}, {'x': 122, 'y': '57'}, {'x': 144, 'y': '101'}, {'x': 166, 'y': '87'}, {'x': 188, 'y': '8'}, {'x': 210, 'y': '180'}, {'x': 232, 'y': '132'}, {'x': 257, 'y': '190'}, {'x': 276, 'y': '210'}, {'x': 298, 'y': '150'}] abc=json.dumps(data) print data </code></pre> <p>The alert shows also the same:</p> <pre><code>[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object] </code></pre> <p>But this does not work:</p> <pre><code>alert(d3.max(data,function(d) { return d.count;})) </code></pre> <p>Here is my entire code</p> <pre><code>function add_py() { var count = $( "#count" ).val(); $.ajax({ type: "get", url: "abc.py", data: {'count': count}, datatype:"script", async: false, success: function(response) { var data= JSON.parse(response); showGraph(data); }, // success closed error:function(xhr,err) { alert("Error connecting to server, please contact system administator."); } })//ajax closed } function showGraph(de) { alert(de) var mySVG = d3.select("body").append("svg"); mySVG .attr("width", 500) .attr("height", 500); var heightScale = d3.scale.linear() .domain([0, 963]) .range([0, 400]); alert(d3.max(de,function(d) { return d.count;})) var heightScale = d3.scale.linear() .domain([0, d3.max(de,function(d) { return d.count;})]) .range([0, 400]); var myBars = mySVG.selectAll('circle') .data(de) .enter() .append('svg:circle'); myBars .attr('r',20); myBars .attr('cx',function(d,i) {return (i * 22) + 100;}) .attr('cy',function(d,i) {return 400 - heightScale(d.count);}); } </code></pre> <p>I understand a data from js and from python file may behave differently , but how to make python data working same like js data. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload