People who have studied achartengine must know that using Chartfactory to create a chart can use the intent method, and then call startactivity to enable this intent, but the downside is that Is that when you need to dynamically display a chart, he keeps activating the activity, which is very inefficient, because each time the activity is started, a thread is created, although the activity is automatically released, but when your chart is used on a low-memory phone, It's hard to avoid shaking the chart.
And there is a big flaw in this approach: only one chart can be displayed at a time, and this method appears to be weak when multiple charts are needed.
So here's a quick look at another way to create a chart in Achartengine: Create a view.
Take Timechart as an example:
When using, we call Chartfactory.gettimechartview (), which is the same as the parameters within the function and Gettimechartintent (), for those who have used the Gettimechartintent method, Small as you are sure you can quickly master the creation of the view.
The view was created, but how do i show it?
To show this view, we need to define a layout in the resource file and then load the view into the layout we defined.
It is believed that many people who have done the Android layout are aware of linearlayout usage. I'll step through how to create a layout and display the view on the screen.
First copy the Main.xml, paste it under res/layout/and name it Chartshow.xml
Modify the content inside
Add a layout
<linearlayout
Android:id= "@+id/chart_show"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:orientation= "Horizontal"
android:layout_weight= "1"
/>
Don't delete that frame linearlayout ah, I just learned the view display when the entire file is emptied, and then copy the above layout code into the file, the result.
Then in your OnCreate () function, you need to load your layout control, and here's a reminder that the layout is also a control, and other controls need to be used by him.
Load this layout
LinearLayout linearview= (linearlayout) Findviewbyid (r.id.chart_show);
Create View,getdemochartgraphicalview This is the method code that I created myself:
Public Graphicalview Getchartgraphicalview (context context) {
Return Chartfactory.gettimechartview (context, DataSet, renderer, "hh-mm-ss");
//}
Graphicalview Chartview=demo.getdemochartgraphicalview (this);
Creating a view requires a context handle, which is the same as when creating a intent,
Then we need to load the view into the Linearview.
Calling function: AddView
The first parameter is the view created above, and the second parameter is the view's properties in the layout.
Don't mess with LinearLayout's attributes.
Linearview.addview (ChartView,
New Layoutparams (layoutparams.fill_parent,layoutparams.fill_parent));
Well, the view is now ready to use, is it a simple feeling?
Display multiple charts, dynamic display chart using view is much more efficient and much more convenient than using intent.
As for the chart creation method, I think everybody understands, here I also did not say more, put a picture which I looked up from the net, the picture will be very clear.
As a simple explanation, creating a table starts with a series set , and then you need to define a renderer seriesrenderer to outline the lines you want to describe or the way the other icons represent them.
The series and renderer determine how a data is painted on a table, but to apply it directly to chartfactory, we also need a multiseriessrenderer and Multiseriesdataset,
As in the previous use of Jfreechart, creating a table requires a dataset rather than a set of data, and then the Seriesrenderer and series are added separately to the Multiseriessrenderer and Multiseriesdataset.
Well, that's it, hey, please continue to pay attention to the small small blog Oh.
Achartengine using the View display chart