Meriç Akgül
Meriç Akgül

Reputation: 173

How to draw Stacked Bar Chart in Android Application

I am new to Android. I am on a project and trying to draw stacked bar chart. I did so much research about this kind of bar chart but either those didn't work or I couldn't apply the codes to my project. I guess there are two most popular libraries for charts which are AChartEngine and Charts4j. I checked this code (https://code.google.com/p/charts4j/source/browse/tags/v1.2/example/com/googlecode/charts4j/BarChartExample.java#51)- example1 for Charts4j. However, this code ends with 'url', I have my values in my project, I'll use these values to draw the chart and I don't want to have to have internet to show the chart. I want to be independent from the internet. I couldn't implement this code to my project.

Another library I used is AChartEngine and I found this code (https://code.google.com/p/achartengine/source/browse/trunk/achartengine/demo/org/achartengine/chartdemo/demo/chart/SalesStackedBarChart.java). Because the main class extends some other class, I created other class (AbstractDemoChart) and interface (IDemoChart) and wrote the codes. Eclipse didn't give any error but when I run it on Emulator, I got an error which stopped the app and the warning of 'force close' appeared.

The other examples about bar charts are not relevant what I want exactly. As a result, I couldn't find any solution for my application. Can you help me how to draw stacked bar chart for my Android App with the values that I already have and I want to see this chart independently from the internet?

Thanks in advance guys.

Upvotes: 2

Views: 5198

Answers (3)

Dan D.
Dan D.

Reputation: 32391

I suggest you download the AChartEngine demo source code and take a look at SalesStackBarChart. Then, on the last line, you can change Type.STACKED to Type.HEAP for an even better stacked bar charts experience.

Upvotes: 1

Nick
Nick

Reputation: 8317

Androidplot supports stacked bar charts as well. Screenshot from the Androidplot demo app on the play store:

enter image description here

Upvotes: 1

phemt.latd
phemt.latd

Reputation: 1803

i don't know native android library or extensions to do that, can be difficult to find a good one ore implement a new other. For this i think that you have just used a library HTML/CSS/Javascript.

I think that you can implement with a js library the graph, for example Javascript graph , charge the html/js files in assets and charge it into a web view with this:

html app in android

The only problem is to find a way to pass data to the html, i think that is it possibile in various way, with bridge or using files.

Upvotes: 1

Related Questions