我的数据调用可以包含许多我想忽略的小元素(百分比),我只需要在我的amCharts饼中排在前5位。
这可以用amCharts完成,还是我应该先处理数据?
请看我的[jsfiddle] [1]
[1]: http://jsfiddle.net/pbarros/xznxbnc7/3/
感谢
答案 0 :(得分:1)
您可以使用hideLabelsPercent
property为您想要标签的最低允许百分比设置阈值。如果您想动态执行此操作,可以在init
事件中设置此项,方法是查找图表percents
中的第五大chartData
array值并将其用作hideLabelsPercent
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();
}
}
1}}门槛。我已经更新了你的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.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/xznxbnc7/9/
编辑因为我误读了这个问题
如果您只想显示数据集中的前五个切片,则可以在后端进行过滤,或使用init方法对dataProvider进行排序和修改,使其仅包含前五个。
def populate_table_data(self):
self.sub_names, self.fullpaths = get_chars_info()
items = zip(self.sub_names, self.fullpaths)
for index, (sub_name, fullpath) in enumerate(items):
new_path = QtGui.QTableWidgetItem(fullpath)
self.character_table.setItem(index, 0, new_path)
new_sub_name = read_json(sub_name)
if len(new_sub_name):
combo = QtGui.QComboBox()
combo.addItems(sorted(new_sub_name))
self.character_table.setCellWidget(index, 1, combo)
else:
self.character_table.setRowHidden(index, True)
self.character_table.resizeColumnsToContents()