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.afreechart; | |
import org.afree.chart.AFreeChart; | |
import org.afree.chart.axis.NumberAxis; | |
import org.afree.chart.plot.XYPlot; | |
import org.afree.chart.renderer.xy.XYBarRenderer; | |
import org.afree.data.xy.XYSeries; | |
import org.afree.data.xy.XYSeriesCollection; | |
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); | |
XYSeriesCollection dataset = new XYSeriesCollection(); | |
XYSeries series = new XYSeries("XYSeries"); | |
series.add(1, 1); | |
series.add(2, 2); | |
series.add(3, 3); | |
series.add(4, 4); | |
series.add(5, 5); | |
series.add(6, 6); | |
series.add(7, 7); | |
dataset.addSeries(series); | |
// X軸の定義 | |
NumberAxis domainAxis = new NumberAxis("X軸"); | |
// Y軸の定義 | |
NumberAxis rangeAxis = new NumberAxis("Y軸"); | |
// 折れ線の定義 | |
//XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); | |
XYBarRenderer renderer = new XYBarRenderer(); | |
XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); | |
AFreeChart chart = new AFreeChart(plot); | |
GraphView spcv = (GraphView) findViewById(R.id.graphView1); | |
spcv.setChart(chart); | |
} | |
@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.afreechart; | |
import org.afree.chart.AFreeChart; | |
import org.afree.graphics.geom.RectShape; | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.util.AttributeSet; | |
import android.view.View; | |
public class GraphView extends View { | |
private AFreeChart chart; | |
private RectShape chartArea; | |
public GraphView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
// TODO Auto-generated constructor stub | |
chartArea = new RectShape(); | |
} | |
@Override | |
protected void onSizeChanged(int w, int h, int oldw, int oldh) { | |
super.onSizeChanged(w, h, oldw, oldh); | |
chartArea.setWidth(w); | |
chartArea.setHeight(h); | |
} | |
@Override | |
protected void onDraw(Canvas canvas) { | |
super.onDraw(canvas); | |
this.chart.draw(canvas, chartArea); | |
} | |
public void setChart(AFreeChart chart) { | |
this.chart = chart; | |
} | |
} |
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.example.afreechart.GraphView | |
android:id="@+id/graphView1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" /> | |
</LinearLayout> |
0 件のコメント:
コメントを投稿