Android: I am Using Achartengine Library for Graphs, But Not Able to Integrate Achartengine's Graph View with Android Xml

Android: I am using AChartEngine library for graphs, but not able to integrate achartengine's graph view with android xml?

This is a FAQ for AChartEngine.
The AChartEngine demo application is available for download here: AChartEngine demo

In the demo source code you can see an example on how to embed a chart into an existing view.

Basically, in the activity descriptor .xml file, we have defined the following as a placeholder for the chart. Of course, other user interface components go together with this layout:

ChartDemo/layout/xy_chart.xml near Line 27

<LinearLayout
android:id="@+id/chart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />

We define a local variable:

ChartDemo/src/org.achartengine.chartdemo.demo.chart/XYChartBuilder.java near Line 68

private GraphicalView mChartView;

We instantiate it on the onResume() method of the activity:

ChartDemo/src/org.achartengine.chartdemo.demo.chart/XYChartBuilder.java near Line 163

protected void onResume() {
super.onResume();
if (mChartView == null) {
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
mChartView = ChartFactory.getLineChartView(this, mDataset,
mRenderer);
layout.addView(mChartView, new LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
...
} else {
mChartView.repaint();
}
}

Whenever new data is added (when the user presses the "Add" button in our case, a new point is added in the current series and:

ChartDemo/src/org.achartengine.chartdemo.demo.chart/XYChartBuilder.java near Line 147

if (mChartView != null) {
mChartView.repaint();
}

Positioning a graph using achartengine in an XML file

This is an FAQ in AChartEngine. The solution can be found here.

There is also an example in the demo project. You can download the ACE demo here. It also includes some code demonstrating how to embed a chart inside an XML layout.

Using AChartEngine library for graphs, not able to get value for diffrent x-axis value

public static ArrayList<double[]> Value = new ArrayList<double[]>();

private double[] x = new double[2010];

private double[] y = new double[2010];

int counter = 2005;

How to use achartEngine?

In the ChartFactory class there are several methods that you can use like this:

    GraphicalView gView=ChartFactory.getDoughnutChartView(context,data,renderer);

and similar ones for other graph types like line charts and bar charts. You can then simply call:

    setContentView(gView);

Download the documentation for AChartEngine, its pretty easy to find there.

show more than one chart in achartengine

Take a look at this example. It shows you how to embed a chart inside a view. If you create 3 separate LinearLayouts, you will be able to add 3 charts, one per each LinearLayout.



Related Topics



Leave a reply



Submit