Created
February 19, 2013 04:34
-
-
Save cofearabi/4983145 to your computer and use it in GitHub Desktop.
Android AChartEngine(sample chart using AChartEngine)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity" > | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_centerHorizontal="true" | |
android:layout_centerVertical="true" | |
android:text="@string/hello_world" /> | |
<LinearLayout android:layout_height="wrap_content" | |
android:layout_width="fill_parent" | |
android:layout_weight="1" | |
android:orientation="horizontal" | |
android:id="@+id/chart"/> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.achartengine; | |
import org.achartengine.ChartFactory; | |
import org.achartengine.GraphicalView; | |
import org.achartengine.model.XYMultipleSeriesDataset; | |
import org.achartengine.model.XYSeries; | |
import org.achartengine.renderer.XYMultipleSeriesRenderer; | |
import org.achartengine.renderer.XYSeriesRenderer; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.widget.LinearLayout; | |
public class MainActivity extends Activity { | |
private GraphicalView mChart; | |
private XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset(); | |
private XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); | |
private XYSeries mCurrentSeries; | |
private XYSeriesRenderer mCurrentRenderer; | |
private void initChart() { | |
mCurrentSeries = new XYSeries("Sample Data"); | |
mDataset.addSeries(mCurrentSeries); | |
mCurrentRenderer = new XYSeriesRenderer(); | |
mRenderer.addSeriesRenderer(mCurrentRenderer); | |
} | |
private void addSampleData() { | |
mCurrentSeries.add(1, 2); | |
mCurrentSeries.add(2, 3); | |
mCurrentSeries.add(3, 2); | |
mCurrentSeries.add(4, 5); | |
mCurrentSeries.add(5, 4); | |
mCurrentSeries.add(6, 3); | |
mCurrentSeries.add(7, 5); | |
} | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
protected void onResume() { | |
super.onResume(); | |
LinearLayout layout = (LinearLayout) findViewById(R.id.chart); | |
if (mChart == null) { | |
initChart(); | |
addSampleData(); | |
mChart = ChartFactory.getCubeLineChartView(this, mDataset, mRenderer, 0.3f); | |
layout.addView(mChart); | |
} else { | |
mChart.repaint(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment