d3.js - How to get only those data which have particular code in crossfilter -
i have following dataset
var data= [ {code:501, value:25}, {code:501, value:30}, {code:501, value:30}, {code:501, value:35}, {code:501, value:60}, {code:502, value:25}, {code:502, value:25} ]
i want dataset contains data code 501. tried following code
var ndx=crossfilter(data); var dim1=ndx.dimension(function(d){return d.code}); var filtereddata=dim1.filter(501);
but not working. not returning me data want. tried print returned data using console printed vague things.
function getdata(){ var range = $("#range").val()*1; if(isnan(range)){ alert("kindly enter valid number"); }else{ var data= [ {code:501, value:25}, {code:501, value:30}, {code:501, value:30}, {code:501, value:35}, {code:501, value:60}, {code:502, value:25}, {code:502, value:25} ]; var ndx=crossfilter(data); var dim1=ndx.dimension(function(d){return d.code}); var filtereddata=dim1.filter(range); alert("requested data is\n"+(json.stringify(dim1.top(infinity)))); } }
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.11/crossfilter.js"></script> <input type='text' id='range'> <input type='button' value='getdata' onclick='getdata()'>
i think looking this.... :d
Comments
Post a Comment