Note that there are some explanatory texts on larger screens.

plurals
  1. POPlot graph using multiple database values in Android app
    primarykey
    data
    text
    <p>I am currently using afreechart to plot a graph in my Android app. I am using the TimeSeries graph, that they've exemplified in their sample app. For me, data to be extracted from two databases.Two questions : 1. How to plot this TimeSeries graph using values from my two databases? 2. The whole graph is not as smooth as one would want to. Especially when scrolling or flicking. And hence, it's inconsistent with the app design. Any way I could make it smoother?</p> <p>If the questions above seems unnecessary or in some way wrong, please point me to a way where I can plot a graph using multiple database values, even if it's not using afreechart. Thanks.</p> <p>I tried using simple 'for' loops in createDataset(), like :</p> <pre><code>private static XYDataset createDataset() { mfirstDbHelper.open(); msecondDbHelper.open(); int firstdb_count = (int) DatabaseUtils.queryNumEntries(mfirstDbHelper.mDb,firstDbAdapter.DATABASE_TABLE); int seconddb_count = (int) DatabaseUtils.queryNumEntries(msecondDbHelper.mDb,secondDbAdapter.DATABASE_TABLE); TimeSeriesCollection dataset = new TimeSeriesCollection(); for(int i=1;i&lt;=seconddb_count;i++){ Cursor seconddb = msecondDbHelper.fetchItem(i); TimeSeries s1 = new TimeSeries(seconddb.getString( seconddb.getColumnIndexOrThrow(secondDbAdapter.KEY_ITEMNAME))); for(int j=1;j&lt;=firstdb_count;j++){ Cursor firstdb = mfirstDbHelper.fetchItem(j); int first_sp_id = Integer.parseInt(firstdb.getString( firstdb.getColumnIndexOrThrow(firstDbAdapter.KEY_ID))); if(first_sp_id == i){ int value = Integer.parseInt(firstdb.getString( firstdb.getColumnIndexOrThrow(firstDbAdapter.KEY_VALUE))); String date = firstdb.getString( firstdb.getColumnIndexOrThrow(firstDbAdapter.KEY_DATE)); String dateParts[] = date.split("-"); String day = dateParts[0]; String month = dateParts[1]; String year = dateParts[2]; int d = Integer.parseInt(day); int m = Integer.parseInt(month); int y = Integer.parseInt(year); s1.add(new Day(d,m,y), value); dataset.addSeries(s1); } firstdb.close(); } seconddb.close(); } mfirstDbHelper.close(); msecondDbHelper.close(); return dataset; } } </code></pre> <p>I have changed the Month() in sample to Day(), and have made sure there's no error in that area. Am getting the error:</p> <pre><code>ERROR/AndroidRuntime(706): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kev/com.kev.MyProject}: java.lang.NullPointerException </code></pre> <p>Also, obviously, this code redraws the graph "s1" over and over again. I do not know how to overcome this problem, and the error. Am still fairly new to programming, especially Android app development, so any blunders above, feel free to smack me in the head and correct my code.</p> <p>Oh, one more thing, I can't use startManagingCursor() since it's a DemoView and not Activity. So, don't know if its causing any problems either.</p> <p>Afreechart TimeSeries sample: <a href="http://code.google.com/p/afreechart/source/browse/#svn%2Ftrunk%2Fafreechart_sample%2Fsrc%2Forg%2Fafree%2Fchart%2Fdemo" rel="nofollow">http://code.google.com/p/afreechart/source/browse/#svn%2Ftrunk%2Fafreechart_sample%2Fsrc%2Forg%2Fafree%2Fchart%2Fdemo</a></p> <p>Afreechart TimeSeries sample - View: <a href="http://code.google.com/p/afreechart/source/browse/trunk/afreechart_sample/src/org/afree/chart/demo/view/TimeSeriesChartDemo01View.java" rel="nofollow">http://code.google.com/p/afreechart/source/browse/trunk/afreechart_sample/src/org/afree/chart/demo/view/TimeSeriesChartDemo01View.java</a></p> <p>Thanks again, for your time. :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload