dc.js : 다른 입력 임계 값을 사용하여 원형 차트의 데이터 분포를 변경하는 방법은 무엇입니까?

Woodran

입력 필드의 점수를 사용하여 원형 차트의 데이터 분포를 변경하고 싶습니다.

예를 들어 scoreThreshold 0.5의 분포 "71 % High / 28 % Low"는 scoreThreshold 0.7의 "42 % High / 57 % Low"로 변경됩니다.

이 예제를 여기 에서 만들었지 만 결과는 만족스럽지 않았습니다. 입력 필드에 0.5를 입력하고 "check!"를 클릭하면 원형 차트 분포가 변경되지 않습니다.

이것은 분배를 결정합니다.

//##  pie chart
var coreCount = ndx.dimension(function (d) {
    var maxNumber=80;
    if (typeof scoreThreshold!='number') {scoreThreshold=0.5}
    //console.log(scoreThreshold)
    if (d.scores >maxNumber*scoreThreshold)
        {return 'High';}
    else {return 'Low';}
    });

coreCount 함수를 갱신하여 입력 점수 임계 값을 사용하여 배포를 다시 할당하고 싶습니다. 그러나 작동하지 않습니다.

$('#scoreThresholdBt').click(function () { 
            scoreThreshold=document.getElementById('scoreThreshold').value
            scoreThreshold=parseFloat(scoreThreshold);
            console.log(scoreThreshold,typeof scoreThreshold);
            function redo_coreCount () {
                var coreCount = ndx.dimension(function (d) {
                    var maxNumber=80;
                    console.log(scoreThreshold);
                    if (d.count >maxNumber*scoreThreshold)
                        {return 'High';}
                    else {return 'Low';}
                    });
            }; redo_coreCount();
            coreCount.group();/**/
            dc.renderAll();
            dc.redrawAll();
        });

이 기능을 어떻게 실현할 수 있습니까? 도움을 주셔서 정말 감사합니다.

고든

기본적으로 새 차원을 즉시 버려지는 임시 변수에 넣습니다. coreCount클릭 기능에서 글로벌 수준에서 동일한 이름을 가진 변수와 관련이 없습니다.

마찬가지로은 coreCount.group()행동이 아닙니다. 사용하지 않으면 손실되는 그룹 개체를 구성하고 있습니다.

새 측정 기준 및 그룹을 차트에 할당해야합니다 coreCount. 글로벌 또는 로컬 값을 추적하지 않기 때문 입니다.

따라서 입력에서 점수 임계 값을 읽는 것을 기반으로 새 차원을 반환하도록 함수를 변경해 보겠습니다.

function coreCount_from_threshold() {
  var scoreThreshold=document.getElementById('scoreThreshold').value;
  scoreThreshold=parseFloat(scoreThreshold);
  console.log(scoreThreshold,typeof scoreThreshold);
  if (isNaN(scoreThreshold)) {scoreThreshold=0.5}
  return ndx.dimension(function (d) {
    var maxNumber=80;
    if (d.scores >maxNumber*scoreThreshold)
        {return 'High';}
    else {return 'Low';}
    });
}

isNaN여기에서 사용해야 합니다.typeof NaN === 'number'

초기화시이 두 가지를 모두 사용할 수 있습니다.

var coreCount = coreCount_from_threshold();

그리고 클릭 :

$('#scoreThresholdBt').click(function () { 
    coreCount.dispose();
    coreCount = coreCount_from_threshold();
    coreCountGroup = coreCount.group();
    coreYesNoPieChart
      .dimension(coreCount)
      .group(coreCountGroup);
    dc.redrawAll();
});

동일한 전역 변수에 할당 coreCount하고 있습니다 coreCountGroup( var여기서는 사용하지 않기 때문에 ). 먼저 이전 차원을 삭제합니다. 그렇지 않으면 계속해서 리소스를 필터링하고 차지하게됩니다. 그런 다음 새 차원과 그룹을 차트에 할당합니다 (그렇지 않으면 해당 항목에 대해 알 수 없기 때문).

dc.js 차트는 새 데이터를 가져올 때만 업데이트 할 수 있기 때문에 여기서 다시 그리기 (렌더링 아님) 만 수행하면됩니다.

여기 당신의 바이올린 작업 포크가 있습니다 .

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관