@Override public void onCreate(Bundle savedInstanceState) { // android boilerplate stuff super.onCreate(savedInstanceState); setContentView(R.layout.dynamicxyplot_example); // get handles to our View defined in layout.xml: dynamicPlot = (XYPlot) findViewById(R.id.dynamicXYPlot); plotUpdater = new MyPlotUpdater(dynamicPlot); // only display whole numbers in domain labels dynamicPlot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0")); // getInstance and position datasets: data = new SampleDynamicXYDatasource(); SampleDynamicSeries sine1Series = new SampleDynamicSeries(data, 0, "Sine 1"); SampleDynamicSeries sine2Series = new SampleDynamicSeries(data, 1, "Sine 2"); LineAndPointFormatter formatter1 = new LineAndPointFormatter(Color.rgb(0, 0, 0), null, null, null); formatter1.getLinePaint().setStrokeJoin(Paint.Join.ROUND); formatter1.getLinePaint().setStrokeWidth(10); dynamicPlot.addSeries(sine1Series, formatter1); LineAndPointFormatter formatter2 = new LineAndPointFormatter(Color.rgb(0, 0, 200), null, null, null); formatter2.getLinePaint().setStrokeWidth(10); formatter2.getLinePaint().setStrokeJoin(Paint.Join.ROUND); // formatter2.getFillPaint().setAlpha(220); dynamicPlot.addSeries(sine2Series, formatter2); // hook up the plotUpdater to the data model: data.addObserver(plotUpdater); // thin out domain tick labels so they dont overlap each other: dynamicPlot.setDomainStepMode(XYStepMode.INCREMENT_BY_VAL); dynamicPlot.setDomainStepValue(5); dynamicPlot.setRangeStepMode(XYStepMode.INCREMENT_BY_VAL); dynamicPlot.setRangeStepValue(10); dynamicPlot.setRangeValueFormat(new DecimalFormat("###.#")); // uncomment this line to freeze the range boundaries: dynamicPlot.setRangeBoundaries(-100, 100, BoundaryMode.FIXED); // create a dash effect for domain and range grid lines: DashPathEffect dashFx = new DashPathEffect(new float[] {PixelUtils.dpToPix(3), PixelUtils.dpToPix(3)}, 0); dynamicPlot.getGraphWidget().getDomainGridLinePaint().setPathEffect(dashFx); dynamicPlot.getGraphWidget().getRangeGridLinePaint().setPathEffect(dashFx); }
@Override public int size() { return datasource.getItemCount(seriesIndex); }
@Override public Number getY(int index) { return datasource.getY(seriesIndex, index); }
@Override public void onPause() { data.stopThread(); super.onPause(); }