need help in integrating achart-engine with database for android


Can u please help me in creating a simple bar chart (for android) where the values are got from sqlite database. for eg consider the following table

year Units Sold 2001 2000 2002 2100 2003 1900

I need to create a bar graph with x-axis as year and y-axis as units sold . Can u Plz consider this as a request . I dont know how to import data from database .


first you have to fetch the values from the data base and stored into array with corresponding data type . Do like this.....

List<int[]> initial; int[] my_year; int[] my_units_sold; public void onCreate() { int Column1 = net_db_cur.getColumnIndex("Year"); int Column2 = net_db_cur.getColumnIndex("Units Sold"); cur = sampleDB.rawQuery("SELECT * FROM " + Table_Name , null); my_year = new int[columncount]; my_units_sold = new int[columncount]; if (cur.moveToFirst()) { for (int i = 0; i < columncount; i++) { my_year [i] = net_db_cur.getInt(Column1); my_units_sold[i] = net_db_cur.getInt(Column2); cur.moveToNext(); } } initial = new ArrayList<int[]>(); initial1.add(my_year); initial1.add(my_units_sold); ll.addView(createBarChart(initial ,Color.BLUE,10,0,14,2000000,20000000,1,x_axis_labels1,x_axis_labels2,y_axis_labels1, y_axis_net_labels2,Color.parseColor("#ffffff"))); } public View createBarChart(int[] values,int[] colors,int lable_text_size,int xMin,int xMax,int yMin,int yMax,double bar_space,double[] x_axis_lables1,String[] x_axis_lables2,double[] y_axis_lables1,String[] y_axis_lables2, int lable_color) { XYMultipleSeriesRenderer mrenderer = new XYMultipleSeriesRenderer(); XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); /*for (int i = 0; i <values.length; i++) {*/ CategorySeries series = new CategorySeries(""); /*double[] v = values.get(i); int seriesLength = v.length;*/ for (int k = 0; k < values.length; k++) { series.add(values[k]); } dataset.addSeries(series.toXYSeries()); //} //mrenderer.setMargins(new int[] { 10, 65, 10, 15 }); int color_length = colors.length; for (int i = 0; i < color_length; i++) { SimpleSeriesRenderer r = new SimpleSeriesRenderer(); r.setColor(colors[i]); r.setChartValuesSpacing(15); mrenderer.addSeriesRenderer(r); } mrenderer.setOrientation(Orientation.HORIZONTAL); mrenderer.setInScroll(false); mrenderer.setGridColor(Color.BLACK); mrenderer.setYLabelsAlign(Align.RIGHT); mrenderer.setPanEnabled(false, false); mrenderer.setZoomEnabled(false, false); mrenderer.setBarSpacing(bar_space); mrenderer.setLabelsTextSize(lable_text_size); mrenderer.setAxesColor(Color.BLACK); mrenderer.setXAxisMin(xMin); mrenderer.setXAxisMax(xMax); for(int i=0;i<x_axis_lables2.length;i++) { mrenderer.addXTextLabel(x_axis_lables1[i],x_axis_lables2[i]); } mrenderer.setYAxisMin(yMin); mrenderer.setYAxisMax(yMax); for(int j=0;j<y_axis_lables1.length;j++) { mrenderer.addYTextLabel(y_axis_lables1[j],y_axis_lables2[j]); } mrenderer.setLabelsColor(lable_color); return (ChartFactory.getBarChartView(Income.this, dataset, mrenderer, Type.DEFAULT)); }

You will get the bar chart for with data base values. All the best.


  • How to create extension for SQL Server Management Studio 17 in C# in VS2017?
  • Delete duplicates entries in SQLite
  • Android - Cursor onMapReady (Markers)
  • how to retrieve value from the SQLite database?
  • need help in integrating achart-engine with database for android
  • Adding timestamp column in importing data in redshift using AWS Glue Job
  • Android SQLite column and index best practice
  • Decrementing a value not working
  • How to close a cursor used in a for loop
  • Text/template: “can't call method/function with 0 results.”
  • Android Contacts on listview
  • Raw query with multiple parameters
  • Error on SELECT*FROM statement android SQLite Database
  • access unkown columns of a table and insert them into a new one
  • How do I Return a Runnable in this Method?
  • Android: Display Multiple Pieces of Cursor Data Together in TextViews instead of a ListView
  • How can i read the db in my android app which i've modified in my pc and copied back to my app&
  • C++, read and write to a binary file at the same time
  • Progress Bar of DownloadManager with percentage
  • Why does my stored procedure throw error 'No data - zero rows fetched, selected, or processed&#
  • MySQLi using an IN in a where
  • sql1 to get names and sql2 to get Impressions, I need to sort names by Impressions
  • How to export MS Access table into a csv file in Python using e.g. pypyodbc
  • How to convert single element tuple into string?
  • Get last call details from Call Log
  • Index Multiple Columns w/ Ruby on Rails
  • How to merge 2 or more columns into one?
  • Select from table that does not exist
  • Pre-populated SQLite Database not reading properly in Android Studio
  • Python pandas melting data to multiple columns and coulmn names in another column
  • Invalid Date on validation Date of js
  • MySQL Order by column = x, column asc?
  • TFS: Get latest causes slow project reloading
  • Updated Ionic CLI but shows previous version (Windows)
  • Display Images one by one with next and previous functionality
  • ORA-29908: missing primary invocation for ancillary operator
  • How to get next/previous record number?
  • What do the 'size' numbers mean in the windbg !heap output?
  • How do you join a server to an Active Directory (domain)?
  • How does Linux kernel interrupt the application?