在xAxis MPChart中获取重复值 [英] Getting duplicate values at xAxis MPChart

查看:64
本文介绍了在xAxis MPChart中获取重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正面临这个问题.我在xAxis的第一个和最后一个中得到重复的值,并且图形值与各个x轴值处的值不同. 第二个问题是,如果我不想以浮点数显示值,而是以int Rounded值显示,并将其颜色更改为白色.

Right Now I am facing this issue. I am getting repeated values in xAxis the first one and the last one.And graph values are not according to the values at respective x-axis values. and the second issue is if I want to display the values not in float but in int Rounded and change the their color to white.

ArrayList<String> xlabels = new ArrayList<String>();
        xlabels.add("Jan");
        xlabels.add("Feb");
        xlabels.add("Mar");
        xlabels.add("Apr");
        xlabels.add("May");
        xlabels.add("Jun");

        ArrayList<String> values = new ArrayList<String>();
        values.add("1");
        values.add("20");
        values.add("10");
        values.add("80");
        values.add("90");
        values.add("24");

        showLineChart(clickChart,xlabels,values,mColors[3]);

showLineChart方法:

private void showLineChart(LineChart chart,final List<String> xLabels, List<String> values,int color){
        List<Entry> entries = new ArrayList<Entry>();
        for(int i=0;i<values.size();i++){
            entries.add(new Entry(i, Integer.parseInt(values.get(i))));
        }



        LineDataSet dataSet = new LineDataSet(entries, "Numbers");
        dataSet.setLineWidth(1.75f);
        dataSet.setCircleRadius(5f);
        dataSet.setCircleHoleRadius(2.5f);
        dataSet.setColor(Color.WHITE);
        dataSet.setCircleColor(Color.WHITE);
        dataSet.setHighLightColor(Color.WHITE);
        dataSet.setDrawValues(true);


        LineData data = new LineData(dataSet);
        ((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(color);

        chart.getDescription().setEnabled(false);

        chart.setDrawGridBackground(false);

        chart.setTouchEnabled(true);

        chart.setBorderColor(Color.WHITE);

        chart.setDragEnabled(true);
        chart.setScaleEnabled(true);


        chart.setPinchZoom(false);

        chart.setBackgroundColor(color);

        YAxis yAxisLeft = chart.getAxisLeft();
        yAxisLeft.setTextColor(Color.WHITE);
        yAxisLeft.setAxisLineColor(Color.WHITE);


        YAxis yAxisRight = chart.getAxisRight();
        yAxisRight.setTextColor(Color.WHITE);
        yAxisRight.setAxisLineColor(Color.WHITE);

        XAxis xAxis = chart.getXAxis();
        xAxis.setTextColor(Color.WHITE);
        xAxis.setAxisLineColor(Color.WHITE);
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setAvoidFirstLastClipping(false);
        xAxis.isDrawLabelsEnabled();
        xAxis.setDrawGridLines(false);
        xAxis.setValueFormatter(new IAxisValueFormatter() {

            @Override
            public String getFormattedValue(float value, AxisBase axis) {

                return xLabels.get((int)value);
            }


        });
        chart.animateX(2500);
        chart.setData(data);
        chart.invalidate();
    }

推荐答案

我要解决相同的问题,请添加以下行:

I was facing the same issue to resolve it add the following line:

xAxis.setGranularityEnabled(true);

检查链接以获得有关Axis的更多详细信息.

Check the link for more details about Axis.

这篇关于在xAxis MPChart中获取重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆