MPAndroidChart设置中心垂直线 [英] MPAndroidChart set center vertical line

查看:160
本文介绍了MPAndroidChart设置中心垂直线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像这样在LineChart的中心设置一条垂直线:

I want to set a vertical line in center of LineChart like this:

滚动到每个点时,它会通知您更改下面的日期(橙色日期字段).通过单击箭头按钮,它可以以编程方式向左或向右移动.

When scrolling to each point, it can notify to change the date below (the orange date field). And it can move left or right programmatically by click on arrow button.

当前,我可以设置视口并允许使用以下代码移至中心:

Currently, I can set viewport and allow moving to center with this code:

LineData data = new LineData(xVals, dataSets);
mChart.setScaleMinima((float) data.getXValCount() / 7f, 1f);
mChart.moveViewTo(0, 7, YAxis.AxisDependency.LEFT);

得到结果:

我如何绘制并设置一条像上面的垂直线?

How can I draw and set a vertical line like above?

更新:

对于听众,我认为OnChartGestureListener onChartTranslate(MotionEvent me, float dX, float dY)可能会有所帮助.我需要的是2点之间的距离以及如何计算当前视口中有多少点.有人知道吗?

For the listener, I think OnChartGestureListener onChartTranslate(MotionEvent me, float dX, float dY) may help. What I need is the distance between 2 points and how to calculate how many points are in current view port. Does anyone know that?

推荐答案

您是否尝试过使用

Have you tried using getEntryByTouchPoint on your chart supplying the x and y coordinates of the center of the chart?

public Entry getEntryByTouchPoint(float x, float y)

返回在图表的触摸位置显示的Entry对象

returns the Entry object displayed at the touched position of the chart

这篇关于MPAndroidChart设置中心垂直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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