2016-09-29 1 views
0

私のデータコールには、私が無視したいと思う小さな要素(パーセンテージ)がたくさんあることがあります。私はamChartsのパイの中でトップ5しか必要としません。amCharts pieの5つの値だけを使用しますか?

これはamChartsで実行できますか、それとも前にデータを処理する必要がありますか?

私は[jsfiddle] [1]

[1]: http://jsfiddle.net/pbarros/xznxbnc7/3/ 

おかげ

答えて

1

あなたは、あなたがのためにラベルをしたい最低の許可率のしきい値を設定するにはhideLabelsPercent propertyを使用することができます参照してください。これを動的に実行する場合は、イベントでこれを設定することができます。これは、の5番目に大きいpercentsの値を見つけて、hideLabelsPercentのしきい値として使用します。私はこれを行うには、あなたのhandleInit方法を更新しました:

function handleInit(e) { 
    if (e.chart.chartData.length > 5) { 
    //sort the copy of the chartData array from largest to smallest 
    //if your data is pre-sorted, then you can skip this step 
    var sortedData = e.chart.chartData.slice().sort(function(lhs, rhs) { 
     return rhs.percents - lhs.percents; 
    }); 

    //set the threshold equal to the 5th largest slice's percents value so that the rest are hidden 
    e.chart.hideLabelsPercent = sortedData[4].percents; 

    //redraw the chart 
    e.chart.validateNow(); 
    } 
} 

更新フィドル:http://jsfiddle.net/xznxbnc7/9/

編集あなただけの上位5つのスライスを表示したい場合、私は疑問

を読み違えているので、あなたのバックエンドでフィルタリングするか、initメソッドを使用してdataProviderをソートして変更し、上位5つだけを含むようにすることができます。

function handleInit(e) { 
    if (e.chart.chartData.length > 5) { 
    //sort the copy of the chartData array from largest to smallest 
    //if your data is pre-sorted, then you can skip this step 
    var sortedData = e.chart.dataProvider.slice().sort(function(lhs, rhs) { 
     return rhs[e.chart.valueField] - lhs[e.chart.valueField]; 
    }); 

    //only put in the top 5. 
    e.chart.dataProvider = sortedData.slice(0, 5); 

    // redraw the chart 
    e.chart.validateData(); 
    } 
} 

フィドル:http://jsfiddle.net/g3cchyjg/1

+0

はmuch..but本当に途中ので、ありがとう、あなたが実際にスライスを見るので、私は私がAJAX呼び出しを行うとmakeChart前・デ・データを選択することがより良い選択肢だと思います – PauloB

+0

@PauloB - ああ、私は5つのスライスだけを表示したいと誤解しました。私はそのケースを処理するために私の答えを更新しました。 – xorspark

+0

ええ、それは本当に私が必要なものでした! – PauloB

関連する問題