Quickstart を参考にやってみる
ライブラリ:androidplot-core-0.6.0.jarをhttp://androidplot.com/download/ からダウンロードしてくる。
プロジェクトを作成する。
libs フォルダにライブラリを入れる。
レイアウトファイル activity_main.xml を作成する。
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
<LinearLayout 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" > | |
<com.androidplot.xy.XYPlot | |
android:id="@+id/mySimpleXYPlot" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</LinearLayout> |
グラフィカルレイアウト画面ではエラーが確認できるが、よく分からないので無視して進む。
この時点で実行すると下記のように表示される。
グラフデータをセットする。
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.androidplottest; | |
import java.util.Arrays; | |
import com.androidplot.xy.LineAndPointFormatter; | |
import com.androidplot.xy.SimpleXYSeries; | |
import com.androidplot.xy.XYPlot; | |
import com.androidplot.xy.XYSeries; | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.view.Menu; | |
public class MainActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
//ビューの取得 | |
XYPlot plot = (XYPlot) findViewById(R.id.mySimpleXYPlot); | |
//グラフのデータ Yの値 | |
Number[] series1Numbers = {1, 8, 5, 2, 7, 4}; | |
// Turn the above arrays into XYSeries': | |
XYSeries series1 = new SimpleXYSeries( | |
Arrays.asList(series1Numbers), // SimpleXYSeries takes a List so turn our array into a List | |
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value | |
"Series1"); | |
LineAndPointFormatter series1Format = new LineAndPointFormatter(); | |
plot.addSeries(series1, series1Format); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.main, menu); | |
return true; | |
} | |
} |
色々調整してみる
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.androidplottest; | |
import java.text.DecimalFormat; | |
import java.util.Arrays; | |
import com.androidplot.ui.SizeLayoutType; | |
import com.androidplot.ui.SizeMetrics; | |
import com.androidplot.xy.BoundaryMode; | |
import com.androidplot.xy.LineAndPointFormatter; | |
import com.androidplot.xy.PointLabelFormatter; | |
import com.androidplot.xy.SimpleXYSeries; | |
import com.androidplot.xy.XYPlot; | |
import com.androidplot.xy.XYSeries; | |
import com.androidplot.xy.XYStepMode; | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.graphics.Color; | |
import android.view.Menu; | |
public class MainActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
//ビューの取得 | |
XYPlot plot = (XYPlot) findViewById(R.id.mySimpleXYPlot); | |
//グラフのデータ Yの値 | |
Number[] series1Numbers = {1, 8, 5, 2, 7, 4 ,6 ,3}; | |
// Turn the above arrays into XYSeries': | |
XYSeries series1 = new SimpleXYSeries( | |
Arrays.asList(series1Numbers), // SimpleXYSeries takes a List so turn our array into a List | |
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value | |
"Series1"); | |
//ラインの色 ポイントの色 塗りつぶし色 の設定 | |
LineAndPointFormatter series1Format = new LineAndPointFormatter(); | |
series1Format.setPointLabelFormatter(new PointLabelFormatter()); | |
series1Format.configure(getApplicationContext(), | |
R.xml.line_point_formatter_with_plf1); | |
plot.addSeries(series1, series1Format); | |
plot.setPlotMargins(0, 0, 0, 20);//ビューのマージン | |
plot.setPlotPaddingBottom(5);//ビューのパディング | |
plot.setTitle("タイトル");//タイトル | |
plot.setGridPadding(0, 10, 10, 0);//left, top, right, bottom グリッドのパディング | |
plot.getGraphWidget().setMarginBottom(10);//グラフと凡例の隙間 | |
//凡例の調整 | |
plot.getLegendWidget().setSize(new SizeMetrics (20, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE )); | |
//Y軸目盛 | |
plot.setRangeBoundaries(0.0, 10.0, BoundaryMode.FIXED);//Y軸目盛0-10 | |
plot.setRangeValueFormat(new DecimalFormat("0"));//整数 | |
// X軸目盛 | |
plot.setDomainBoundaries(0, 8, BoundaryMode.FIXED);//目盛0から8 | |
plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL,2);//目盛のステップ | |
//グリッドとメモリの色 | |
plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.BLACK);//グリッドの背景 | |
plot.getGraphWidget().getDomainGridLinePaint().setColor(Color.MAGENTA);//グリッドの縦線の色 | |
plot.getGraphWidget().getRangeGridLinePaint().setColor(Color.CYAN);//グリッドの横線の色 | |
plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLUE);//Y軸目盛の線 | |
plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.WHITE);//X軸目盛の線 | |
plot.getGraphWidget().getDomainLabelPaint().setColor(Color.GRAY);//X軸の目盛の文字色 | |
plot.getGraphWidget().getRangeLabelPaint().setColor(Color.YELLOW);//Y軸の目盛の文字色 | |
plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.GREEN);//X軸の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.main, menu); | |
return true; | |
} | |
} |
ラインの色、太さ、ポイントの色、塗り潰し色、文字の色
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
<?xml version="1.0" encoding="utf-8"?> | |
<config | |
linePaint.strokeWidth="3dp" | |
linePaint.color="#00AA00" | |
vertexPaint.color="#ff0000" | |
fillPaint.color="#00000000" | |
pointLabelFormatter.textPaint.color="#FFFFFF"/> |
0 件のコメント:
コメントを投稿