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/aprLevelsPlot" | |
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.BarFormatter; | |
import com.androidplot.xy.BoundaryMode; | |
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.graphics.Color; | |
import android.view.Menu; | |
public class MainActivity extends Activity { | |
private XYPlot plot; | |
private SimpleXYSeries aprLevelsSeries; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
plot = (XYPlot) findViewById(R.id.aprLevelsPlot); | |
//aprLevelsSeries = new SimpleXYSeries("APR Levels"); | |
//aprLevelsSeries.useImplicitXVals(); | |
Number[] series1Numbers10 = {3, 8, 5}; | |
Number[] series1Numbers = series1Numbers10; | |
XYSeries series1 = new SimpleXYSeries(Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Us"); | |
plot.addSeries(series1, new BarFormatter(Color.BLUE, Color.BLACK)); | |
plot.setRangeBoundaries(0, 10, BoundaryMode.FIXED); | |
} | |
@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; | |
} | |
} |
QuickstartのDynamically Plotting Sensor Dataのソースを見ながら調整していく。
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.text.FieldPosition; | |
import java.text.Format; | |
import java.text.ParsePosition; | |
import java.util.Arrays; | |
import com.androidplot.ui.SizeLayoutType; | |
import com.androidplot.ui.SizeMetrics; | |
import com.androidplot.xy.BarFormatter; | |
import com.androidplot.xy.BarRenderer; | |
import com.androidplot.xy.BarRenderer.BarWidthStyle; | |
import com.androidplot.xy.BoundaryMode; | |
import com.androidplot.xy.SimpleXYSeries; | |
import com.androidplot.xy.XYPlot; | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.graphics.Color; | |
import android.util.Log; | |
import android.view.Menu; | |
public class MainActivity extends Activity { | |
private XYPlot plot; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
plot = (XYPlot) findViewById(R.id.aprLevelsPlot); | |
Number[] series1Numbers = {3, 8, 5}; | |
SimpleXYSeries series1 = new SimpleXYSeries(Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Sensor"); | |
plot.addSeries(series1, new BarFormatter(Color.BLUE, Color.BLACK)); | |
plot.setDomainStepValue(3); | |
plot.setDomainLabel("Axis"); | |
plot.setRangeBoundaries(0, 10, BoundaryMode.FIXED);//Y軸 0-10 | |
plot.setRangeValueFormat(new DecimalFormat("0"));//整数 | |
//グリッド | |
plot.setGridPadding(20, 10, 20, 0);//left, top, right, bottom グリッドのパディング | |
plot.setPlotPaddingBottom(10);//ビューのパディング | |
plot.getGraphWidget().setMarginBottom(10);//グラフと凡例の隙間 | |
//凡例の調整 | |
plot.getLegendWidget().setSize(new SizeMetrics (20, SizeLayoutType.ABSOLUTE, 100, SizeLayoutType.ABSOLUTE )); | |
//Y目盛り表示変更 | |
Format myFormat = new Format(){ | |
@Override | |
public StringBuffer format(Object object, StringBuffer buffer, FieldPosition field) { | |
// TODO Auto-generated method stub | |
Number num = (Number) object; | |
int roundNum = (int) num.floatValue() ; | |
switch(roundNum) { | |
case 0: | |
buffer.append("Azimuth"); | |
break; | |
case 1: | |
buffer.append("Pitch"); | |
break; | |
case 2: | |
buffer.append("Roll"); | |
} | |
return buffer; | |
} | |
@Override | |
public Object parseObject(String string, ParsePosition position) { | |
// TODO Auto-generated method stub | |
return null; | |
}}; | |
plot.setDomainValueFormat( myFormat ); | |
//BarRenderer の取得 変更 | |
BarRenderer<?> barRenderer = (BarRenderer<?>) plot.getRenderer(BarRenderer.class); | |
if(barRenderer != null) { | |
Log.v("----","OK"); | |
barRenderer.setBarWidth(10); | |
//barRenderer.get | |
barRenderer.setBarWidthStyle(BarWidthStyle.FIXED_WIDTH); | |
//barRenderer.setBarGap(-30); | |
} | |
//データの変更 | |
Number[] series1NumbersNew = {8, 5, 1}; | |
series1.setModel(Arrays.asList(series1NumbersNew), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); | |
} | |
@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; | |
} | |
} |
0 件のコメント:
コメントを投稿