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.StackedXYBarRenderer; | |
import org.afree.data.xy.DefaultTableXYDataset; | |
import org.afree.data.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); | |
XYSeries series1 = new XYSeries("First", true, false); | |
series1.add(1, 10); | |
series1.add(2, 0); | |
series1.add(3, 30); | |
series1.add(4, 40); | |
series1.add(5, 50); | |
XYSeries series2 = new XYSeries("Second", true, false); | |
series2.add(1, 50); | |
series2.add(2, 40); | |
series2.add(3, 30); | |
series2.add(4, 20); | |
series2.add(5, 10); | |
DefaultTableXYDataset dataset = new DefaultTableXYDataset(); | |
dataset.addSeries(series1); | |
dataset.addSeries(series2); | |
// X軸の定義 | |
NumberAxis domainAxis = new NumberAxis("X軸"); | |
// Y軸の定義 | |
NumberAxis rangeAxis = new NumberAxis("Y軸"); | |
// 折れ線の定義 | |
//XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); | |
StackedXYBarRenderer renderer = new StackedXYBarRenderer(); | |
renderer.setMargin(0.2); | |
renderer.setShadowVisible(false);//影 | |
XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); | |
AFreeChart chart = new AFreeChart(plot); | |
NumberAxis numberAxis = (NumberAxis) plot.getDomainAxis(); | |
numberAxis.setLowerBound(0); | |
numberAxis.setUpperBound(6); | |
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; | |
} | |
} |