Пример #1
0
  @SuppressWarnings("deprecation")
  public void drawGraph(
      XYPlot plot, List<Number> xseries, List<Number> yseries, String datatitle, String title) {
    //		Log.d(SystemInfo.TIG, TAG + "::drawGraph()");

    // set up data series
    plot.removeSeries(series);

    series = new SimpleXYSeries(xseries, yseries, datatitle);

    // create a formatter
    // TODO solve deprecation waring
    LineAndPointFormatter format =
        new LineAndPointFormatter(
            Color.rgb(0, 200, 0) // line color
            ,
            Color.rgb(0, 100, 0) // point color
            ,
            Color.rgb(150, 190, 150)); // fill color (optional)

    // add series1 and series2 to the XYPlot
    plot.addSeries(series, format);

    // Reduce the number of range labels
    plot.setTicksPerRangeLabel(3);
    plot.getBackgroundPaint().setAlpha(0);
    plot.getGraphWidget().getBackgroundPaint().setAlpha(0);
    plot.getGraphWidget().getGridBackgroundPaint().setAlpha(0);

    // TODO implement an on-the-fly refresh of the plot
    // this is just a small "stubbed" redraw for demonstration purposes
    plot.setDomainStepMode(XYStepMode.SUBDIVIDE);
    plot.setDomainStepValue(1);
    plot.setGridPadding(0, 5, 0, 5);

    plot.setDomainLabel("Time [s]");
    if (title.equals(SystemInfo.DB_TABLENAME_BATTERY)) {
      plot.setTitle(SystemInfo.DB_TABLENAME_BATTERY);
      plot.setRangeLabel("[%]");
      plot.setRangeBoundaries(0, 100, BoundaryMode.FIXED);

    } else if (title.equals(SystemInfo.DB_TABLENAME_WIFI)) {
      plot.setTitle(SystemInfo.DB_TABLENAME_WIFI);
      plot.setRangeLabel("[~mW]");
      plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED);

    } else if (title.equals(SystemInfo.DB_TABLENAME_THREEG)) {
      plot.setTitle(SystemInfo.DB_TABLENAME_THREEG);
      plot.setRangeLabel("[~mW]");
      plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED);

    } else if (title.equals(SystemInfo.DB_TABLENAME_BLUETOOTH)) {
      plot.setTitle(SystemInfo.DB_TABLENAME_BLUETOOTH);
      plot.setRangeLabel("[~mW]");
      plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED); // XXX scale
    }
    plot.redraw();
  }
  @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);
  }
    // Constructor sets up the series
    public mPlotUpdater(XYPlot plot) {
      this.plot = plot;
      // only display whole numbers in domain labels
      plot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0"));

      // Line plot
      if (dispForm == "WAVE") {
        LineAndPointFormatter maxFormat =
            new LineAndPointFormatter(
                Color.rgb(0, 25, 250), // line color
                Color.rgb(0, 25, 250), // point color
                null); // fill color (optional)

        LineAndPointFormatter minFormat =
            new LineAndPointFormatter(
                Color.rgb(250, 25, 0), // line color
                Color.rgb(250, 25, 0), // point color
                null); // fill color (optional)

        LineAndPointFormatter audioFormat =
            new LineAndPointFormatter(
                Color.rgb(25, 250, 0), // line color
                Color.rgb(25, 250, 0), // point color
                null); // fill color (optional)

        plot.addSeries(audioHistSeries, audioFormat);
        plot.addSeries(maxSeries, maxFormat);
        plot.addSeries(minSeries, minFormat);
      }
      // Bar plot
      if (dispForm == "FFT") {
        plot.addSeries(
            audioHistSeries,
            BarRenderer.class,
            new BarFormatter(Color.argb(100, 0, 200, 0), Color.rgb(0, 80, 0)));
      }

      // thin out domain/range tick labels so they don't overlap each other:
      plot.setGridPadding(5, 0, 5, 0);
      plot.setTicksPerDomainLabel(5);
      plot.setTicksPerRangeLabel(3);
      plot.disableAllMarkup();

      // freeze the range boundaries:
      plot.setDomainStepMode(XYStepMode.INCREMENT_BY_VAL);
      plot.setDomainStepValue(1);
      plot.setTicksPerRangeLabel(6);
      if (dispForm == "WAVE") plot.setDomainLabel("Time");
      if (dispForm == "FFT ") plot.setDomainLabel("Frequency");
      plot.getDomainLabelWidget().pack();
      plot.setRangeLabel("Amplitude");
      plot.getRangeLabelWidget().pack();
      plot.disableAllMarkup();
    }