0

There is a functionality to set maximum number of visible entries with

mChart.setVisibleXRangeMaximum(5);

but is there a way to maintain the same resolution or step size when in landscape mode, where the chart becomes longer?

By resolution / step size I mean the physical screen space between x-values.

adriennoir
  • 1,329
  • 1
  • 15
  • 29

1 Answers1

1

This can be achieved by setting the x-range minimum and maximum according to the chart width, which changes during orientation change. For example:

   final int visibleXRange = pxToDp(mChart.getWidth()) / someMagicNumberFactorOfYourPreference;

   mChart.setVisibleXRangeMaximum(visibleXRange);
   mChart.setVisibleXRangeMinimum(visibleXRange);

...

public int pxToDp(int px) {
    DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
    int dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return dp;
}
adriennoir
  • 1,329
  • 1
  • 15
  • 29