Search code examples
androidachartengine

Chart with Bar and Line not matching values on X-axis


I have searching a lot on Internet but I have not found a solution to my problem.

The issue is the following: I'm trying to make a Combined chart, in which there is a LineChart and a BarChart.

When I have, for example, these values, it works fine:

double[] valuesXaxisGraph1 = new double[]{1,2,3,4,5};
double[] dataGraph1 = new double[]{5,5,5,5,5};
double[] valuesXaxisGraph2 = new double[]{1,2,3,4,5}
double[] dataGraph2 = new double[]{6,6,6,6,6};

The graph created is the following:

http://i.imgur.com/tZm82mW.png

However, if I use these values:

double[] valuesXaxisGraph1 = new double[]{1,2,3,4,5,6,7,8,9,10};
double[] dataGraph1 = new double[]{5,5,5,5,5,5,5,5,5,5};
double[] valuesXaxisGraph2 = new double[]{1,2,3,4,5};
double[] dataGraph2 = new double[]{6,6,6,6,6};

The graph shown is the following:

graph

As you can see, the bars appears from 1 to 10, instead from 1 to 5. Because of that, these bars aren't positioned where they should be (1, 2, 3, 4...).

Why is happening this? What should I do to fix it?

Thanks in advance.


Solution

  • You can set the range for the second scale to be the same for the first scale. For instance, for setting the X axis maximum value, you would do:

    renderer.setXAxisMax(renderer.getXAxisMax(0), 1);