Exemple #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;
  }
Exemple #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;
  }
Exemple #3
0
  /**
   * Creates a sample chart.
   *
   * @param data the sample data.
   * @return A configured chart.
   */
  private static AFreeChart createChart() {
    XYDataset data = createDataset();
    AFreeChart chart =
        ChartFactory.createXYLineChart(
            "Marker Demo 01", "Time", "Value", data, PlotOrientation.VERTICAL, false, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis valueAxis = plot.getRangeAxis();
    PeriodAxisLabelInfo[] info = new PeriodAxisLabelInfo[2];

    info[0] =
        new PeriodAxisLabelInfo(
            Hour.class,
            new SimpleDateFormat("HH"),
            new RectangleInsets(0, 0, 25, 0),
            valueAxis.getLabelFont(),
            valueAxis.getAxisLinePaintType(),
            true,
            valueAxis.getAxisLineStroke(),
            valueAxis.getAxisLinePaintType());
    info[1] =
        new PeriodAxisLabelInfo(
            Day.class,
            new SimpleDateFormat("dd-MMM"),
            new RectangleInsets(0, 0, 0, 0),
            valueAxis.getLabelFont(),
            valueAxis.getLabelPaintType(),
            false,
            valueAxis.getAxisLineStroke(),
            valueAxis.getLabelPaintType());

    PeriodAxis domainAxis =
        new PeriodAxis(null, new Hour(0, 18, 10, 2011), new Hour(23, 18, 10, 2011));

    domainAxis.setLabelInfo(info);
    plot.setDomainAxis(domainAxis);

    PaintType paintRed = new SolidColor(Color.RED);
    PaintType paintGreen = new SolidColor(Color.GREEN);

    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setRange(0, 100);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaintType(0, paintGreen);
    renderer.setSeriesStroke(0, 2.0f);

    // add a marker
    Marker marker_H = new ValueMarker(50.0);
    marker_H.setLabelOffsetType(LengthAdjustmentType.EXPAND);
    marker_H.setPaintType(paintRed);
    marker_H.setStroke(2.0f);
    plot.addRangeMarker(marker_H);

    // add range marker
    Hour hour1 = new Hour(11, 18, 10, 2011);
    Hour hour2 = new Hour(13, 18, 10, 2011);
    double millis1 = hour1.getFirstMillisecond();
    double millis2 = hour2.getFirstMillisecond();
    Marker marker_V = new IntervalMarker(millis1, millis2);
    marker_V.setLabelOffsetType(LengthAdjustmentType.EXPAND);
    marker_V.setPaintType(new SolidColor(Color.rgb(150, 150, 255)));
    plot.addDomainMarker(marker_V, Layer.BACKGROUND);

    Marker marker_V_Start = new ValueMarker(millis1, Color.BLUE, 2.0f);
    Marker marker_V_End = new ValueMarker(millis2, Color.BLUE, 2.0f);
    plot.addDomainMarker(marker_V_Start, Layer.BACKGROUND);
    plot.addDomainMarker(marker_V_End, Layer.BACKGROUND);
    return chart;
  }