我有一个大约有10个x轴标签的数据集。我的条形图未在我的x轴上显示所有标签。
仅显示第一个和最后一个标签。我必须在条形图中显示所有10个x轴标签。
xAxis1.setValueFormatter(new IndexAxisValueFormatter(taskTypes));
xAxis1.setGranularity(1);
xAxis1.setLabelCount(11);
private void setData_chart(int count, float range) {
float barWidth = 10f;
float spaceForBar = 12f;
ArrayList<BarEntry> values = new ArrayList<>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range);
values.add(new BarEntry(i * spaceForBar, val,
getResources().getDrawable(R.drawable.ic_launcher)));
}
BarDataSet set1;
if (chart1.getData() != null &&
chart1.getData().getDataSetCount() > 0) {
set1 = (BarDataSet) chart1.getData().getDataSetByIndex(0);
set1.setValues(values);
chart1.getData().notifyDataChanged();
chart1.notifyDataSetChanged();
}
[1:After updated with the below code graph is displaying like this
用于(PickListValues pickListValues1:pickListValues){
value = pickListValues1.getValue();
label=pickListValues1.getLabel();
//PickListValues pickListValues2=new PickListValues(value,label);
//pickListTask.add(pickListValues2);
taskTypes.add(value);
Log.d("tasktype", String.valueOf(taskTypes));
xAxis1.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
return String.valueOf(taskTypes);
}
});
您可以尝试这些
1-
@Override
public String getFormattedValue(float value) {
if (value < 0 || value > taskTypes.size() - 1) {
return ""
}
return taskTypes.get((int)value);
}
2-
xAxis1.setLabelRotationAngle(90f);
3-
xAxis1.setTextSize(8f);
4-
String valueStr = taskTypes.get((int)value);
return valueStr.length() > 6 ? valueStr.substring(0,6) : valueStr;