두 개의 드롭 다운이 있습니다. 드롭 다운 중 하나에서 선택이 수행 될 때마다 crossect 함수가 호출되어 loadData 및 loadData1.My 코드가 여기에 첨부 된 함수가 호출되기를 원합니다.드롭 다운을 사용하는 교차 필터
<select onchange="intersect()" id="metric" class="wrapper-dropdown">
<option value ="190">190</option>
<option value ="90">90</option>
<option value ="100">100</option>
<option value ="300">300</option>
</select>
<select onchange="intersect()" id="metric1" class="wrapper-dropdown">
<option value ="100">100</option>
<option value ="200">200</option>
<option value ="0">0</option>
</select>
<script>
var intersect= function() {
var total_90 = function() {
var data = [
{date: "2011-11-14T16:17:54Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T16:20:19Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa"},
{date: "2011-11-14T16:30:43Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:48:46Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:53:41Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:54:06Z", quantity: 1, total: 100, tip: 0, type: "cash"},
{date: "2011-11-14T16:58:03Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:07:21Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:22:59Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:25:45Z", quantity: 2, total: 200, tip: 0, type: "cash"},
{date: "2011-11-14T17:29:52Z", quantity: 1, total: 200, tip: 100, type: "visa"}
];
var ndx = crossfilter(data);
var totalDim = ndx.dimension(function(d) { return d.total; });
var total_90 = totalDim.filter(document.getElementById('metric').selectedOptions[0].value);
return total_90;
};
var tip_90 = function() {
var data = [
{date: "2011-11-14T16:17:54Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T16:20:19Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa"},
{date: "2011-11-14T16:30:43Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:48:46Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:53:41Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:54:06Z", quantity: 1, total: 100, tip: 0, type: "cash"},
{date: "2011-11-14T16:58:03Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:07:21Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:22:59Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:25:45Z", quantity: 2, total: 200, tip: 0, type: "cash"},
{date: "2011-11-14T17:29:52Z", quantity: 1, total: 200, tip: 100, type: "visa"}
];
var ndx = crossfilter(data);
var tipDim = ndx.dimension(function(d) { return d.tip; });
var tip_90 = tipDim.filter(document.getElementById('metric1').selectedOptions[0].value);
return tip_90;
}
var result = [];
for (var i = 0; i < total_90.length; i++){
if (total_90[i].total == 90 && total_90[i].tip == 0)
{
result.push(total_90[i]);
}
}
for (var i = 0; i < tip_90.length; i++){
if (tip_90[i].total == 90 && tip_90[i].tip == 0)
{
result.push(tip_90[i]);
}
}
function print_filter(filter){
var f=eval(filter);
if (typeof(f.length) != "undefined") {}else{}
if (typeof(f.top) != "undefined") {f=f.top(Infinity);}else{}
if (typeof(f.dimension) != "undefined") {f=f.dimension(function(d) { return "";}).top(Infinity);}else{}
console.log(filter+"("+f.length+") = "+JSON.stringify(f).replace("["," [\n\t").replace(/}\,/g,"},\n\t").replace("]","\n]"));
}
print_filter("result");
}
</script>
</body>
그래서, 주어진 예에서 나는 '0'벌써 내가 가지고있는 JSON 배열 모두에서 모든 행을 원 아래로 두 번째 드롭에서 선택한 첫 번째 드롭 다운에서 '90'를 선택한 경우 total = 90 및 tip = 0이 콘솔에 인쇄됩니다. 내가 여기 너무 어려운 것을 잘 모릅니다
왜 d3이 필요한가요? 교차 필터는 드롭 다운의 값 중 하나가 변경 될 때 변경해야하는 그래픽 및 표 형식의 값을 플롯해야하기 때문입니다. 실제로, 아직 추가되지 않은 드롭 다운이 꽤 많이 있습니다. 나는이 모든 코딩과 새로운 것들에 익숙하지 않다. 그래서, 나는 내가 보는 모든 옵션으로 놀고있다. 결국 드롭 다운이있는 그래프와 테이블을 플로팅 할 때 나를 도울 수있는 더 좋은 것을 제안 할 수 있습니까? –
'd3.js'를 사용하면 최신 브라우저를 사용하는 경우 데이터 시각화에 좋지 않습니다. – jhyap
†! 코드를 약간 수정하여 데이터 집합이 선택되도록 추가 드롭 다운을 추가했습니다. . 세 가지 필터 중 하나가 변경 될 때마다 값을 콘솔에 인쇄해야합니다. 여기서 내가 뭘 잘못하고 있니? [링크] (http://jsfiddle.net/vjLZ9/) –