Grafik pada android
Grafik adalah salah satu komponen yang di mana berguna untuk penyajian data yang bisa berupa garis, chart, pie dll. di android kita juga bisa membuat grafik tersebut dengan menggunakan library HoloGraph, Untuk implementasi bisa lihat code di bawah ini
package com.example.tesholograp;
import com.echo.holographlibrary.Line;
import com.echo.holographlibrary.LineGraph;
import com.echo.holographlibrary.LinePoint;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Menu;
import android.widget.TextView;
@SuppressLint("NewApi")
public class Lineeee extends Activity {
TextView x,y;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lineeee);
x=(TextView)findViewById(R.id.x);
y=(TextView)findViewById(R.id.y);
Line l = new Line();
LinePoint p = new LinePoint();
ActionBar actionBar = getActionBar();
actionBar.setTitle("Grafik Penjualan");
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FF5722")));
p.setX(0);
p.setY(5);
l.addPoint(p);
p = new LinePoint();
p.setX(8);
p.setY(8);
l.addPoint(p);
p = new LinePoint();
p.setX(10);
p.setY(4);
l.addPoint(p);
l.setColor(Color.parseColor("#CC0000"));
x.setText("x :"+p.getX()+" ");
y.setText("y:"+p.getY());
LineGraph li = (LineGraph)findViewById(R.id.graph);
li.addLine(l);
li.setRangeY(0, 10);
li.setLineToFill(0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.lineeee, menu);
return true;
}
}
Untuk XML
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/AbsoluteLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#BDBDBD"
tools:context=".Lineeee" >
<com.echo.holographlibrary.LineGraph
android:id="@+id/graph"
android:layout_width="294dp"
android:layout_height="138dp"
android:layout_x="14dp"
android:layout_y="75dp"
android:background="#ffffff" />
<LinearLayout
android:layout_width="294dp"
android:layout_height="30dp"
android:layout_x="14dp"
android:layout_y="39dp"
android:background="#ffffff"
android:orientation="horizontal" >
<TextView
android:id="@+id/x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/y"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="294dp"
android:layout_height="18dp"
android:layout_x="14dp"
android:layout_y="22dp"
android:background="#ffffff"
android:orientation="vertical" >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#33B5E5"
android:text=" Real Time Coordinate "
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff" />
</LinearLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="14dp"
android:layout_y="74dp"
android:background="#33B5E5"
android:text=" Real Time Graph "
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff" />
</AbsoluteLayout>
Komentar
Posting Komentar