MP Android图表-如何在折线图中固定X轴值的数量? [英] MP Android Chart-How to fix the number of X-Axis values in the Line Chart?

查看:252
本文介绍了MP Android图表-如何在折线图中固定X轴值的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void plotchart(String s[], float[] f1) {
    chart.setBackgroundColor(Color.rgb(63, 81, 181));
    chart.setDescription("");
    // enable touch gestures
    chart.setTouchEnabled(true);
    chart.setScaleEnabled(false);
    chart.setPinchZoom(false);
    chart.setGridBackgroundColor(Color.rgb(30, 46, 141));
    chart.setDrawGridBackground(false);
    chart.getAxisRight().setEnabled(false);
    chart.setDrawMarkerViews(true);
    chart.setDragEnabled(true);
    chart.setViewPortOffsets(0f, 0f, 0f, 0f);

   // chart.setVisibleXRangeMaximum(4);


    chart.getLegend().setEnabled(false);

    XAxis x = chart.getXAxis();
    x.setEnabled(true);
    x.setDrawGridLines(false);
    x.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
    x.setTextColor(Color.rgb(128, 128, 255));
    x.isDrawLabelsEnabled();
    x.setAxisLineColor(Color.BLACK);
    x.setSpaceBetweenLabels(3);
    x.setAvoidFirstLastClipping(true);


    YAxis y = chart.getAxisLeft();
    y.setAxisLineColor(Color.BLACK);
    y.setTextColor(Color.BLACK);
    y.setEnabled(true);
    y.setAxisLineColor(Color.rgb(128, 128, 255));
    y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    y.setDrawGridLines(false);
    y.setLabelCount(5,true);
    y.setGridColor(Color.rgb(128, 128, 255));
    y.setDrawZeroLine(false);
    y.setDrawLimitLinesBehindData(true);
    y.setDrawGridLines(true);
    y.setDrawLimitLinesBehindData(true);
    y.setTextColor(Color.rgb(128, 128, 255));
//    chart.setExtraOffsets(20f,2f,20f,2f);

    ArrayList<com.github.mikephil.charting.data.Entry> entries= new ArrayList<>();
    for (int i = 0; i < f1.length; i++) {
        // Log.i("f1",f1[i]+"");
         entries.add(new com.github.mikephil.charting.data.Entry(f1[i], i));
    }

    MymarkerView mv =new MymarkerView(this,R.layout.custom_marker_view);
    chart.setMarkerView(mv);

    LineDataSet dataset = new LineDataSet(entries, "");
    dataset.isDrawCirclesEnabled();
    dataset.setCircleRadius(0f);
    dataset.setDrawFilled(true);
    dataset.setFillColor(Color.rgb(0, 0, 0));
    dataset.setLineWidth(0.2f);
    dataset.setValueTextSize(0f);

    dataset.setColor(Color.rgb(0, 0, 0));

  //  chart.setVisibleXRange(1, 5);
   // chart.setVisibleYRangeMaximum(5, YAxis.AxisDependency.LEFT);
  //  chart.setClickable(true);
    chart.invalidate();


    ArrayList<String> time = new ArrayList<String>();
    for (int i = 0; i < s.length; i++) {
        time.add(i, s[i]);
    }

    LineData data = new LineData(time, dataset);
    chart.setData(data);


}

我已经使用setLabelCount()命令固定了Y轴值.但是如何固定图表中的X轴值.对于上面的代码,我形成了以下图表. http://i.stack.imgur.com/KJMKA.png"rel =" noreferrer>图表1

I Have fixed the Y-Axis values by using setLabelCount() command.But how to fix the number of X-Axis values in my chart..For the above code i have the following chart formed.Chart1 Chart2..These are the two charts formed for different arguments given to the plotchart(String [],float[]) method.In all these charts I am facing the problem that it is not showing the fixed number of x-axis values.Somewhere it is showing 9 values and somewhere it is showing 7 values..And one more issue I am facing is that my first and the last Y-Axis values are getting hidden in my display.

推荐答案

setLabelCount()属性也适用于xAxis.

setLabelCount() property is there for xAxis too.

 XAxis xAxis = lineChart.getXAxis();
 xAxis.setLabelCount(5);

这篇关于MP Android图表-如何在折线图中固定X轴值的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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