Java – Use different x-axis labels for the n lines in the graph

Use different x-axis labels for the n lines in the graph… here is a solution to the problem.

Use different x-axis labels for the n lines in the graph

So I use MPAndroidChart as a library to view charts in my app. Now I want to make a LineGraph with multiple lines (n). The problem is that the rows don’t have the same x-axis labels, and I haven’t found a solution to associate x-axis labels with entries. Also, whether the new row starts with an x value of 0. As a result, my rows don’t fill the entire chart area. Because when I have two rows with 6 entries each, the size of the x-axis labels is 12. Therefore, these lines end halfway through the chart.

How do I fix it?

Example LineGraph

Solution

I’m assuming you’re referring to the library available here: https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java

From the code I have, LineChart doesn’t support dual x-axes (but it does, left and right). See also here, XAxis.java and YAxis.java

On the other hand, it looks like the x-axis automatically fits into the data range (there is no way to set the min/max value of the x-axis).

Example chart

I recommend that you reorganize the chart to switch the x-axis and y-axis, and use two y-axes if your series has different ranges of y-values, but you want to display them in the chart. In my experience, dual y-axis is more common and easier to understand than dual x-axis.