AFreeChart
グラフの再描画には、invalidate()を使用します。 グラフ描画のクラスのサンプルコードです。 private class GraphManager { public GraphManager () { }; public void displayGraph (TimeSeries series, float target, float min, float max ) { if (target …
折れ線の太さと色を変える // 折れ線の太さと色を変える。XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();renderer.setSeriesStroke(0, 5.0f);renderer.setSeriesPaintType(0, new SolidColor(Color.rgb(255, 166, 0)));plot.setRenderer(…
Y軸(値軸)のデータレンジを決める。 ValueAxis yAxis = plot.getRangeAxis();yAxis.setRange(100.0d, 320.0d);
X軸(時間軸)の目盛間隔を変えるサンプルコードです。 // X軸の目盛間隔を変える。DateAxis xAxis = (DateAxis)plot.getDomainAxis();xAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 2, new SimpleDateFormat("yyyy/MM")));
Y軸(値軸)の目盛間隔を変えるサンプルコードです。 XYPlot plot = chart.getXYPlot(); // Y軸の目盛間隔を変える。ValueAxis yAxis = plot.getRangeAxis();TickUnits ty = new TickUnits();TickUnit uniY = new NumberTickUnit(20);ty.add(uniY);yAxis.setSt…
グラフの4隅にマージンを持たせるサンプルコードです。 AFreeChart chart = ChartFactory.createTimeSeriesChart( "PV推移", "月", "PV", data, false, // ← 凡例無し false, false);// グラフの右側にマージンを持たせる。RectangleInsets insets = new Rec…
Y軸(値軸)のマーカーの設定のサンプルコードです。 // Y軸のマーカーの表示Marker marker = new ValueMarker(170);PaintType makerColor = new SolidColor(Color.rgb(180, 0, 180));marker.setPaintType(makerColor);marker.setStroke(2.0f);marker.setLabel…
凡例の消去のサンプルコードです。 AFreeChart chart = ChartFactory.createTimeSeriesChart( "PV推移", "月", "PV", data, false, // ← 凡例無し false, false); あるいは // 凡例の消去chart.removeLegend();
グラフタイトルのフォント指定 AFreeChart chart = ChartFactory.createTimeSeriesChart( "PV推移", "月", "PV", data, false, // ← 凡例無し false, false);// グラフのラベルを変えるTextTitle title = chart.getTitle();title.setFont(new Font(Typeface.…
軸のフォントの指定 XYPlot plot = chart.getXYPlot(); // 軸の目盛のフォントを変える。Font xyAxisFont = new Font(Typeface.SANS_SERIF, Typeface.BOLD, 30);plot.getRangeAxis().setTickLabelFont(xyAxisFont);plot.getDomainAxis().setTickLabelFont(xy…
1.グラフのViewを準備するクラス public class GraphView extends View { private AFreeChart chart; private RectShape chartArea; public GraphView(Context context, AttributeSet attrs) { super(context, attrs); chartArea = new RectShape(); } @Ov…
1.AFreeChartのダウンロード https://code.google.com/p/afreechart/downloads/list 上記URL から、 afreechart-0.0.4.jar をダウンロードし、プロジェクトのlibsフォルダに入れる。 2.build.gradleへの追加 dependencies { compile fileTree(dir: 'libs…