Reputation: 13
I'd like to combine a bar chart with 2 data series and a line chart in AChartEngine but I was not able to do that. In the AChartEngine demo I found only an example which combines a single series bar chart and a line Chart (Combined temperature).
What I'd like: https://i.sstatic.net/IBq9w.jpg
If I define 3 series (2 for bar chart, 1 for line chart) in a dataset for a combined XY chart like this:
ChartFactory.getCombinedXYChartView(ctx, dataset, renderer, new String[] { BarChart.TYPE, BarChart.TYPE, LineChart.TYPE });
...then I get this result: https://i.sstatic.net/YVozj.jpg
If I define 3 series and 2 chart types:
ChartFactory.getCombinedXYChartView(ctx, dataset, renderer, new String[] { BarChart.TYPE, LineChart.TYPE });
...then I get an exception:
java.lang.IllegalArgumentException: Dataset, renderer and types should be not null and the datasets series count should be equal to the types length
at org.achartengine.ChartFactory.getCombinedXYChartView(ChartFactory.java:202)
Do I misunderstand something or does AChartEngine simply not support a multiple series bar chart and a line chart in combination?
Upvotes: 1
Views: 2363
Reputation: 32391
Starting from the "Combined temperature" example in the AChartEngine demo, you can keep a LineChart
and a BarChart
the way they are and add a new BarChart
. The x axis values for the two bar charts should be a little bit different such as they don't overlap. For instance, if the x
values should be 1
then the first bar chart could add the value at 0.75
and the second one at 1.25
. This way they will be rendered separately.
Also, set the main renderer bar spacing: renderer.setBarSpacing(1);
means that the space between 2 items in the same series is equal to the width of one bar.
Upvotes: 0
Reputation: 784
See this : http://tapt007.hubpages.com/hub/Android-Combined-Charts Hope it helps you.
Upvotes: 1