hellocharts-android icon indicating copy to clipboard operation
hellocharts-android copied to clipboard

How to set a integer Y axis values?

Open Nightonke opened this issue 9 years ago ā€¢ 4 comments

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!

Nightonke avatar Dec 27 '15 08:12 Nightonke

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

TAUnionOtto avatar Jan 06 '16 07:01 TAUnionOtto

TAUnionEd I tried that on my graph, but for some reason my yAxis values look all squished together.

fnoori avatar Jan 07 '16 06:01 fnoori

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);

Ankur008 avatar Oct 06 '16 06:10 Ankur008

@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.

menghuibali avatar Oct 26 '17 08:10 menghuibali