Tuesday, September 23, 2014

I created a project what is the world population called ChartEx Try to create the Android project l


Seek to draw charts in Android I have to start looking outside the library what is the world population to include the Android native API to the conclusion that it must be manually direct the implementation. It was between the interest paid from several pre-built library, a library and free library exists figured haeteotgo Free Library of course. The library will introduce today is called achartengine what is the world population library. You have the ability to express a wide variety of shapes, such as free, yet the graph bar graph, line graph, pie graph is achartengine. You try to use the most basic bar graph from that today. You can download the library from the library, download http://code.google.com/p/achartengine. When you access the site to download the library web page appears as shown below. After you connect to the site, click the Download what is the world population menu.
I created a project what is the world population called ChartEx Try to create the Android project library. You have created a project package name to kr.pe.hoyanet.chartex. Please refer to the posting of the following to create a new Android project in process. After you create [Android TIP] the Hello World project was deleted TextView controls displayed by default /res/layout/main.xml open the file. And we give the value of the id llBody to put the graph in the main LinearLayout cycle through the sources.
To use the graph represents the graph library using the library what is the world population data set method, you need to graph representation of the objects provided by achartengine color, font size, etc., and takes the form of the View object. Then, include in such addView LinearLayout control using the object method. First, we will express the views of the monthly sales subject to look at a simple sample. First look at the results of running the screen appears as below. (S2 Galaxy screenshot.)
Let's look at each step. We put the difference in the color values are used in different parts of the graph. Compare hasimyeonseo you see the colors that appear on the screen and the color value representing the source seems to run faster is to understand the results. We handle all of the following source code in onCreate method of Activity class. Declares as follows: Declaration of data to be displayed on the screen used to display data. Numerical values what is the world population to display // List <double []> values = new ArrayList <double []> (); values.add (new double [] {14230, 12300, 14240, 15244, 15900, 19200, 22030, what is the world population 21200, 19500, 15500, 12600, 14000}); Graphic attributes for the output graph for the graph object produces the output first. Graphic attributes / ** graph output object * / XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer (); Specifies the title to be displayed at the top of the font size. If you do not need a title may be omitted. // Top of the title and text size renderer.setChartTitle ("2011 Year of Sales"); renderer.setChartTitleTextSize (20); Specifies the item name and color to express the numerical what is the world population value (yellow). Is displayed in yellow on first designated a "monthly sales" and any items please pay attention. Name for the classification // String [] titles = new String what is the world population [] {"Monthly Sales"}; Item used to display the color value // int [] colors = new int [] {Color.YELLOW}; Specifies the font size and each color classification name // renderer.setLegendTextSize (15); int length what is the world population = colors.length; for (int i = 0; i <length; i ++) {SimpleSeriesRenderer r = new SimpleSeriesRenderer (); r.setColor (colors [i]); renderer.addSeriesRenderer (r); } X, Y axis, specify what is the world population the item name, and font size. We are being displayed in any position on the Run screen, the text below that specified in the source of an eye check. // X, Y axis item name and font size renderer.setXTitle ("month"); renderer.setYTitle ("sales"); what is the world population renderer.setAxisTitleTextSize (12); The minimum font size and the numeric value of each of X axis, the maximum value range. And specifies the minimum Y-axis, the maximum value of the range. The properties of the numerical value of which is shown as X-axis and Y-axis kkaeal on the graph. // Font size numeric value / X-axis minimum and maximum values / Y axis minimum and maximum values renderer.setLabelsTextSize (10); renderer.setXAxisMin (0.5); renderer.setXAxisMax (12.5); renderer.setYAxisMin (0); renderer.setYAxisMax (24000); Defines the X-axis what is the world population and Y-axis line color. Width, specified as gray vertical lines outside. what is the world population // X, Y axis line color renderer.setAxesColor (Color.WHITE); Top title, X, Y axis titles, specify what is the world population the text color of the numeric value. Specified by CYAN color values. Please pay attention to the items that are displayed (light blue?) Scientology. // Top title, X, Y axis title, text color of the numerical value renderer.setLabelsColor (Color.CYAN); Specifies the X-axis and Y-axis display interval. Specified to display the X-axis is due to the 12 month data. Specified to display 05 items divided into two silkworm is so wide a range of the Y-axis value solder. Value increases, becomes more dense spacing of each figure. // X, Y axis alignment direction renderer.setXLabelsAlign (Align.LEFT); renderer.setYLabelsAlign (Align.LEFT); Specifies other miscellaneous options. Please refer to the comments of each option means. // X, Y axis if the scroll ON / OFF renderer.setPanEnabled (false, false); // ZOOM function ON / OFF renderer.setZoomEnabled (false, false); // ZOOM ratio renderer.setZoomRate (1.0f); Bar spacing between // renderer.setBarSpacing (0.5f); Save a dataset form information last set ever. Has been taken from the demo source code library. It seems to me that the details you want to modify. // Setting information set XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset (); for (int i = 0; i <titles.length; i ++) {CategorySeries series what is the world population = new CategorySeries (titles what is the world population [i]); double [] v = values.get (i); int seriesLength = v.length; for (int k = 0; k <seriesLength; k ++) {series.add (v [k]); } Dataset.addSeries (series.toXYSeries ()); } Generated to include in the graph obtained in the View View and layout what is the world population taken by the graph on the basis of set information before. Is included in the layout when using this method addView View. // Graph object created what is the world population GraphicalView gv = ChartFactory.getBarChartView (this, dataset, renderer, Type.STACKED); // Graph to add a LinearLayout LinearLayout llBody = (LinearLayout) findViewById (R.id.llBody); llBody.addView (gv); If technology in the onCreate () method to run the screen appears all the stages of this form I showed earlier. The following are used to the full source code full source code, the output graph. package kr.pe.hoyanet.chartex; import java.util.ArrayList; import java.util.List; import org.achartengine.ChartFactory; import org.achartengine.GraphicalView; import org.achartengine.chart.BarChart.Type; import org.achartengine.model.CategorySeries; import org.achartengine.model.XYMultipleSeriesDataset; import org.achartengine.renderer.SimpleSeriesRenderer; import org.achartengine.renderer.XYMultipleSeriesRenderer; import android.app.Activity; import what is the world population android.graphics.Color; import android.graphics.Paint.Align; import android.os.Bundle; import android.widget.LinearLayout; public class ChartExActivity extends Activity {Override what is the world population public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentVi

No comments:

Post a Comment