Esempio n. 1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.proxy = new UsbProxy(this.getActivity(), this.mUsbReceiver);
    this.view = inflater.inflate(R.layout.monitor_fragment, container, false);
    this.serie = new TimeSeries("My serie");
    this.dataset = new TimeSeriesCollection();
    this.dataset.addSeries(this.serie);

    this.chart =
        ChartFactory.createTimeSeriesChart(
            "My chart", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            this.dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
            );

    this.chart.setBackgroundPaintType(new SolidColor(Color.WHITE));

    final XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setBackgroundPaintType(new SolidColor(Color.LTGRAY));
    plot.setDomainGridlinePaintType(new SolidColor(Color.WHITE));
    plot.setRangeGridlinePaintType(new SolidColor(Color.WHITE));
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
      final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
      renderer.setBaseShapesVisible(true);
      renderer.setBaseShapesFilled(true);
      renderer.setDrawSeriesLineAsPath(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    this.view = new DemoView(this.getActivity());
    ((DemoView) this.view).setChart(this.chart);

    return this.view;
  }
Esempio n. 2
0
  /**
   * Creates a chart.
   *
   * @param dataset the dataset.
   * @return a chart.
   */
  AFreeChart createChart(XYDataset dataset) {

    AFreeChart chart =
        ChartFactory.createTimeSeriesChart(
            "Heart Data Report", // title
            "heart data", // (red-systolic,blue-diastolic,green-heart-rate)",             // x-axis
                          // label
            "value", // y-axis label
            dataset, // data
            true, // create legend?
            true,
            false // generate URLs?
            );

    chart.setBackgroundPaintType(new SolidColor(Color.GREEN));

    // chart.setBackgroundPaintType( Color.GREEN);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaintType(new SolidColor(Color.LTGRAY));
    plot.setDomainGridlinePaintType(new SolidColor(Color.WHITE));
    plot.setRangeGridlinePaintType(new SolidColor(Color.WHITE));
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
      XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
      renderer.setBaseShapesVisible(true);
      renderer.setBaseShapesFilled(true);
      renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("yyyy/MM/dd/HH:mm:ss")); // MMM-yyyy"));

    ////////////////////////////////
    // plot.setLabelFont(new Font("SansSerif", Typeface.NORMAL, 12));
    // plot.setNoDataMessage("No data available");
    // plot.setCircular(false);
    // plot.setLabelGap(0.02);
    return chart;
  }