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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With