Android: how to create lists under the charts in Achartengine?
Android: Hi, I'm using AchartEngine to display charts in my App
I have tried different ways to display this charts with some lists开发者_开发百科 under the chart in my app, but I haven't. I have no Idea about how to use these charts with defining layouts in xml. I'm able to display the graphs without using the xml layouts.Many Thanks in Advance.
Regards, Harry.
If Achartengine is referenced in your project (or compiled if you are including the source) then you should see the view available in the eclipse layout designer.
Just drag the view onto your layout.
Alternatively you can dynamically create your layout however this will require a little extra work and research
AchartEngine has a class ChartFactory
which is used for creating views or intents.
So, possibly you can set the view returned at desired place in the xml.
This way you can create a xml, here I have a LinearLayout that will contain my Graph.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/list_view" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout android:id="@+id/myLinearLayout"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</LinearLayout>
</LinearLayout>
Now, in Activity class you can show the Graph by getting the id of LinearLayout and adding view to your LinearLayout. In the onItemClick()
of the ListView show the Graph.
XYMultipleSeriesRenderer renderer = Bar_Chart.getBarDemoRenderer();
linear_layout.removeAllViews();
View mView = ChartFactory.getBarChartView(this, Bar_Chart.getBarDemoDataset(), renderer, Type.DEFAULT);
mView.setLayoutParams(new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT) );
linear_layout.addView(mView);
精彩评论