hellocharts-android
hellocharts-android copied to clipboard
How to set a integer Y axis values?
I use hellocharts to draw a chart showing the number of people on each day. But if the number is small, for example, 1 or 2, the Y axis shows float values. How to set Y axis to integer values only? Thanks!
Iām looking for the answer to this question too,I try the following way like:
List<AxisValue> axisValuesWeight = new ArrayList<>(); //it's Y axis value list
for(int i = 0; i < WEIGHT_MAX;i ++) //WEIGHT_MAX is the max of Y values
axisValuesWeight.add(new AxisValue(i).setLabel(i + ""));
axisY = new Axis(axisValuesWeight);
But I have a new problem,the Y of my chart has only one integer to show For example, weight is 66.1,66.9,67.2 and 69.1 There just is 66 in the bottom (but all of the points put in right set,have right distance)
I want to know why
TAUnionEd I tried that on my graph, but for some reason my yAxis values look all squished together.
I know its too late.. but it may help anyone in future.
Axis axisX = new Axis(); ... SimpleAxisValueFormatter formatter = new SimpleAxisValueFormatter(); formatter.setDecimalSeparator(".");//by default taken from locale formatter.setDecimalDigitsNumber("2");//number of digits after decimal separator, for example 1.00, 1.99, by default 0 formatter.setPrependedText("$"); //text added before value, for example $1.99 formatter.setAppendedText("k");//text added after value, for example $1.99k axisX.setFormatter(formatter);
@Nightonke @TAUnionEd @fnoori For your reference. I also suffered the same problem. I try the method @Ankur008 provided and it does not work. But I found another way to solve my problem successfully.
Viewport v = new Viewport(mChartView.getMaximumViewport()); v.top = 10; v.right = 7; mChartView.setMaximumViewport(v); mChartView.setCurrentViewport(v); mChartView.setViewportCalculationEnabled(false);
I found the Y axis values were always divided into ten pieces. The max number is less than 10 and the Y axis will show float values. Then i set Viewport.top as 10 when the number less than it. Fortunately, it works.