Reputation: 636
I am displaying realtime chart which should display values as per second. My X axis is time in second. But I am not able to display fixed time interval in x axis ie. 0,1,2,... so on. X axis value is automatically calculated and time interval between two x values goes to 20 seconds which I don't want. I need your help to fix this.
Any help would be greatly appreciated.
Upvotes: 13
Views: 21354
Reputation: 1320
Theres an alternative solution to this that will work on the normal MPAndroidChart (iOS or Android). You can manually set the range covered by the axis, by using axisMinimum and axisMaximum properties. You can also set the number of axis labels by using setLabelCount. With a combination of these, you can get even intervals in-between axis labels. For example, with an axisMinimum of 0, an axisMaximum of 100, and setLabelCount set with 5 labels, you end up with a label at the top and bottom of the range (0 and 100 respectively), and 3 labels inbetween, which gives you a fixed gap of 25. Swift 3 code:
chart.xAxis.setLabelCount(5, /*force: */true)
chart.xAxis.axisMinimum = 0
chart.xAxis.axisMaximum = 100
Gives you even intervals : 0, 25, 50, 75, 100.
Upvotes: 24
Reputation: 426
Have you tried to set the X-Axis values to a fixed number ?
float minXRange = 10;
float maxXRange = 10;
chart.setVisibleXRange(minXRange, maxXRange);
Upvotes: 0
Reputation: 367
You can use a modified version of the library that allows users to tell the graph which labels should be drawn.
See the example below:
leftAxis.setShowSpecificLabelPositions(true);
leftAxis.setSpecificLabelPositions(new float[]{0, 10, 20, 50, 100, 300});
Reference link: https://github.com/PhilJay/MPAndroidChart/pull/2692
Modified Library link: https://github.com/philippeauriach/MPAndroidChart/tree/custom-labels
Upvotes: 5