X和Y轴打印出现Android MPChart问题 [英] Android MPChart issue with X and Y axis printing

查看:161
本文介绍了X和Y轴打印出现Android MPChart问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MPChart绘制线图.

I am using MPChart for drawing line graph.

下面是我用来绘制图表的代码.该图工作正常.我唯一的问题是我需要在图形的左侧和底部打印x和y轴(即L形).我希望将X值(传递给LineData的值)打印在图形的底部(x轴),并且我想为y轴设置最小值和最大值,并且应该基于此最小值和最小值来调整图形最大值.

Below is the code I used to draw the chart. The graph works fine. The only problem I have is I need to have the x and y axis printed (i.e) L shape on the left and bottom of the graph. I want the X values (thats passed to LineData) to be printed at the bottom of the graph (x-axis) and I want to set minimum and maximum value for the y-axis and the graph should be adjusted based on this min and max value.

如果我取消注释第1行零件并通过true/删除第1行零件.该图格式不正确.有人请帮帮我.

If I uncomment Line 1 part and pass true / remove Line 1 part. The graph becomes malformed. Someone please help me out.

谢谢

heartXVals是一个ArrayList,其中包含heartYVals Entry数据中相应心率值的日期.

heartXVals is the ArrayList containing dates of the corresponding heart rate values in heartYVals Entry data.

heartDataSet = LineDataSet(heartYVals,"")

        heartDataSet!!.setLineWidth(1.75f)
        heartDataSet!!.setCircleSize(3f);
        heartDataSet!!.setColor(Color.WHITE);
        heartDataSet!!.setCircleColor(Color.WHITE);
        heartDataSet!!.setHighLightColor(Color.WHITE);
        heartDataSet!!.setDrawValues(false);

        val dataSets:ArrayList<LineDataSet> = ArrayList();
        dataSets.add(heartDataSet!!);

        val data:LineData = LineData(heartXVals,dataSets)

        val lineChart:LineChart = view.findViewById(R.id.heartChart) as LineChart

        lineChart.setDescription("")
        lineChart.setNoDataTextDescription("You need to provide data for the chart.")
        lineChart.setDrawGridBackground(false)
        lineChart.setTouchEnabled(false)
        lineChart.setDragEnabled(false)
        lineChart.setScaleEnabled(true)

        // if disabled, scaling can be done on x- and y-axis separately
        lineChart.setPinchZoom(false)

        //lineChart.setBackgroundColor(color)

        // set custom chart offsets (automatic offset calculation is hereby disabled)
        lineChart.setViewPortOffsets(10f, 0f, 10f, 0f)


        // add data
        lineChart.setData(data)

        // get the legend (only possible after setting data)
        val l = lineChart.getLegend()
        l.setEnabled(false)

        lineChart.getAxisLeft().setEnabled(false) -- Line 2

      /*  val leftAxis:YAxis = lineChart.getAxisLeft(); ---Line 1
        leftAxis.removeAllLimitLines()
        leftAxis.setAxisMaxValue(220f);
        leftAxis.setAxisMinValue(40f);
        leftAxis.setStartAtZero(false);
        leftAxis.enableGridDashedLine(0f, 0f, 0f);*/


        lineChart.getAxisRight().setEnabled(false)

        lineChart.getXAxis().setEnabled(false)
        //lineChart.getY.setEnabled(true)

        // animate calls invalidate()...
        lineChart.animateX(2500)

        lineChart.invalidate()

推荐答案

// - X Axis
XAxis xAxis = mChart.getXAxis();
xAxis.setTypeface(tf);
xAxis.setTextSize(12f);
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setTextColor(ColorTemplate.getHoloBlue());
xAxis.setEnabled(true);
xAxis.disableGridDashedLine();
xAxis.setSpaceBetweenLabels(5);
xAxis.setDrawGridLines(false);
xAxis.setAvoidFirstLastClipping(true);

// - Y Axis
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.removeAllLimitLines();
leftAxis.setTypeface(tf);
leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setTextColor(ColorTemplate.getHoloBlue());
leftAxis.setAxisMaxValue(1000f);
leftAxis.setAxisMinValue(0f); // to set minimum yAxis
leftAxis.setStartAtZero(false);
leftAxis.enableGridDashedLine(10f, 10f, 0f);
leftAxis.setDrawLimitLinesBehindData(true);
leftAxis.setDrawGridLines(true);
mChart.getAxisRight().setEnabled(false);


//-----------------
xAxis.setPosition(XAxisPosition.BOTTOM); --- x Axis 
leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART); --- x Axis

这篇关于X和Y轴打印出现Android MPChart问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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