How can MPAndroidChart begin at the last x-value with a large dataset?

北城以北 提交于 2019-12-25 08:22:58

问题


I am using MPAndroidChart library in Android.

I'm trying to get the graph to start at the last set of x values.

I would like to show every day of the year up until now so 1 - 271 (today is the 271st day of the year)

I am using

chart.setVisibleXRangeMaximum(10) 

but the chart begins by showing day 1 - 10 and I want to start by showing day 261 - 271.


回答1:


According to MPAndroidChart's wiki, try

chart.moveViewToX(yourNumberOfXPoints); or chart.moveViewTo(yourNumberOfXPoints);

Why?

moveViewToX(float xValue): Moves the left side (edge) of the current viewport to the specified x-value.

moveViewTo(float xValue, float yValue, AxisDependency axis): This will move the left side of the current viewport to the specified x-value on the x-axis, and center the viewport to the specified y-value on the provided y-axis (makes sense in combination with setVisibleXRange(...) and setVisibleYRange(...).




回答2:


I think you should have to use IAxisValueFormatter

public class MyXAxisValueFormatter implements IAxisValueFormatter {

private String[] mValues;

public MyXAxisValueFormatter(String[] values) {
    this.mValues = values;
}

@Override
public String getFormattedValue(float value, AxisBase axis) {
    // "value" represents the position of the label on the axis (x or y)
    return mValues[(int) value];
}

/** this is only needed if numbers are returned, else return 0 */
@Override
public int getDecimalDigits() { return 0; }}

In this mValues is an array which contains values which you want to set in xAxis. in your case array contains 261 - 271 values.

For more details please see : this



来源:https://stackoverflow.com/questions/39737521/how-can-mpandroidchart-begin-at-the-last-x-value-with-a-large-dataset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!