[第一个和最后一个标签仅在使用MpchartAndroid Libary for Barchart的android中显示

问题描述 投票:0回答:1

我有一个大约有10个x轴标签的数据集。我的条形图未在我的x轴上显示所有标签。

仅显示第一个和最后一个标签。我必须在条形图中显示所有10个x轴标签。

下面是图像的参考when I do pinchzoom with fingers that time I can able to see the remaing Labels.But bars not displaying properly

 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();
        } 

[1After 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);
                                    }


                                });
android bar-chart
1个回答
0
投票

您可以尝试这些

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;
© www.soinside.com 2019 - 2024. All rights reserved.