mpandroidchart - 如何避免在Y轴的重复值? [英] mpandroidchart - How can I avoid the repeated values in Y-Axis?

查看:2480
本文介绍了mpandroidchart - 如何避免在Y轴的重复值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想避免的重复值和Y轴的-0值,避免了图像的情况。

I want to avoid the repeated values and the -0 values in Y-Axis, avoiding the image situation.

我的这些想法解决这个问题,但任何解决方案:

I have these ideas to solve this, but any solution:

  1. 具有Y轴重复的值之前限制变焦,因此停止无限放大,在图表上
  2. 获取的Y轴值并删除重复值。
  1. Limit the zoom before having repeated values in YAxis, therefore stop the infinite zoom-in on the chart
  2. Get the YAxis values and remove the duplicate values.

Y轴与重复值

推荐答案

TL;博士的您可以通过更改标签计数 onChartScale 。

tl;dr You can do this by changing the label count in onChartScale.

首先,你希望你的听众设置:

First, you want your listener set up:

chart.setOnChartGestureListener(this); // set a listener ;)

您尝试获得顶部/底部抽出的价值观和检查什么被绘制在屏幕上。应用一些基本的计算,你设置。

You try to get the top/bottom drawn values and check what gets drawn on the screen. Apply some basic calculations, and you're set.

下面code将利用2个标签,如果缩放水平得到(太)高以及多达9个,否则:

The following code will draw 2 labels if the zoom level gets (too) high and up to 9 otherwise:

@Override
public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
    final YAxis yAxis = mChart.getAxisLeft();
    final Transformer transformer = mChart.getTransformer(YAxis.AxisDependency.LEFT);

    // ...minor dirty hack
    final PointD top = transformer.getValuesByTouchPoint(0, 0);
    final PointD bottom = transformer.getValuesByTouchPoint(0, mChart.getHeight());
    final int diff = (int)(top.y - bottom.y);

    // draw 2-9 axis labels
    final int count = Math.min(9, Math.max(diff, 2));

    Log.d("scale", String.format("scale %f: diff %d and count %d", scaleY, diff, count));

    // "force" the count, for there are drawing issues where none get drawn on high zoom levels (just try it out)
    yAxis.setLabelCount(count, true);
}

// todo implement other interface methods

价值格式化和其他一切保持不变。

The value formatter and everything else stays the same.

和一些丑陋的截图显示,它的工作原理:D

And some ugly screenshot to show that it works :D

放大图表2标签

这篇关于mpandroidchart - 如何避免在Y轴的重复值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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