private void initView(View view) {
    // TODO Auto-generated method stub
    mLightView = (TextView) view.findViewById(R.id.info_light_data);

    XYSeries series = new XYSeries("");
    mDataset.addSeries(series);
    mCurrentSeries = series;
    XYSeriesRenderer renderer = new XYSeriesRenderer();
    mRenderer.addSeriesRenderer(renderer);
    renderer.setPointStyle(PointStyle.CIRCLE);
    renderer.setFillPoints(true);
    renderer.setDisplayChartValues(true);
    renderer.setDisplayChartValuesDistance(20);
    renderer.setChartValuesTextSize(15);
    mCurrentRenderer = renderer;

    // set data
    mCurrentSeries.clear();
    LinearLayout parentLayout = (LinearLayout) view.findViewById(R.id.chart_layout);
    mChartView = ChartFactory.getLineChartView(getActivity(), mDataset, mRenderer);
    parentLayout.addView(
        mChartView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    // 平均值
    Date day = TimeController.getToday();
    day = TimeController.getDayDiffDay(-6, day);
    for (int i = 1; i <= 7; i++) {
      mRenderer.addXTextLabel(i, TimeController.getDayString(day));
      Integer light = getAverageLight(day);
      mCurrentSeries.add(i, light);
      day = TimeController.getTomorrow(day);
    }

    mChartView.repaint();
  }
 private void initRenderer(
     String xTitle,
     double xMin,
     double xMax,
     double yMin,
     double yMax,
     int xLabelsCount,
     int yLabelsCount,
     int checkType) {
   Log.d(TAG, "initRenderer() is called");
   int[] colors = {0xfff74461};
   mRenderer.removeAllRenderers();
   for (int i = 0; i < colors.length; i++) {
     SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
     renderer.setColor(colors[i]);
     renderer.setDisplayChartValues(true);
     // renderer.setDisplayBoundingPoints(true);
     renderer.setChartValuesTextAlign(Align.CENTER);
     renderer.setShowLegendItem(true);
     mRenderer.addSeriesRenderer(renderer);
   }
   ChartViewUtil.initXYMultipleSeriesRenderer(
       mContext,
       mRenderer,
       xTitle,
       "进煤量",
       xMin,
       xMax,
       yMin,
       yMax,
       xLabelsCount,
       yLabelsCount,
       Color.BLACK,
       Color.BLACK);
 }
예제 #3
0
 public void addSegment(View v) {
   mChartView.setOnClickListener(
       new View.OnClickListener() {
         public void onClick(View v) {}
       });
   mRenderer.setZoomEnabled(true);
   mRenderer.setZoomRate(mRenderer.getZoomRate() + 2);
   String seriesTitle = "Series " + (mDataset.getSeriesCount() + 1);
   // create a new series of data
   XYSeries series = new XYSeries(seriesTitle);
   mDataset.addSeries(series);
   mCurrentSeries = series;
   // create a new renderer for the new series
   XYSeriesRenderer renderer = new XYSeriesRenderer();
   mRenderer.addSeriesRenderer(renderer);
   // mRenderer.setZoomButtonsVisible(true);
   // set some renderer properties
   renderer.setPointStyle(PointStyle.CIRCLE);
   renderer.setFillPoints(true);
   renderer.setDisplayChartValues(true);
   renderer.setDisplayChartValuesDistance(40);
   mCurrentRenderer = renderer;
   mChartView.repaint();
   CustomDialog cdd = new CustomDialog(this);
   cdd.show();
 }
예제 #4
0
 @Override
 public Intent execute(Context context) {
   String[] titles = new String[] {"sin + cos"};
   List<double[]> x = new ArrayList<double[]>();
   List<double[]> values = new ArrayList<double[]>();
   int step = 4;
   int count = 360 / step + 1;
   x.add(new double[count]);
   double[] sinValues = new double[count];
   values.add(sinValues);
   for (int i = 0; i < count; i++) {
     int angle = i * step;
     x.get(0)[i] = angle;
     double rAngle = Math.toRadians(angle);
     sinValues[i] = Math.sinh(rAngle);
   }
   int[] colors = new int[] {Color.RED};
   PointStyle[] styles = new PointStyle[] {PointStyle.POINT};
   XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
   setChartSettings(
       renderer,
       "Trigonometric functions",
       "X (in degrees)",
       "Y",
       0,
       360,
       -2,
       2,
       Color.GRAY,
       Color.LTGRAY);
   renderer.setXLabels(20);
   renderer.setYLabels(10);
   return ChartFactory.getLineChartIntent(context, buildDataset(titles, x, values), renderer);
 }
  protected XYMultipleSeriesRenderer buildRenderer(int color, PointStyle style, boolean fill) {
    XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();

    // 设置图表中曲线本身的样式,包括颜色、点的大小以及线的粗细等
    XYSeriesRenderer r = new XYSeriesRenderer();
    r.setColor(color);
    r.setPointStyle(style);
    r.setFillPoints(fill);
    r.setLineWidth(3);
    renderer.addSeriesRenderer(r);

    return renderer;
  }
예제 #6
0
  public LineGraph() {
    // Add datasets to multiple dataset
    mDataset.addSeries(dataset1);
    mDataset.addSeries(dataset2);

    // Customization time for line 1!
    renderer1.setColor(Color.BLUE);
    // renderer.setPointStyle(PointStyle.SQUARE);
    // renderer.setFillPoints(true);
    renderer1.setLineWidth(8);

    // Customization time for line 2!
    renderer2.setColor(Color.RED);
    // renderer.setPointStyle(PointStyle.SQUARE);
    // renderer.setFillPoints(true);
    renderer2.setLineWidth(8);

    // Enable Zoom
    // mRenderer.setZoomButtonsVisible(true);
    mRenderer.setXTitle("Time");
    mRenderer.setYTitle("Temp");

    mRenderer.setAxisTitleTextSize(20);
    mRenderer.setLabelsTextSize(20);
    // mRenderer.setLegendTextSize(30);
    mRenderer.setShowLegend(false);
    mRenderer.setYLabelsAlign(Align.LEFT);

    // Add renderers to multiple renderer
    mRenderer.addSeriesRenderer(renderer1);
    mRenderer.addSeriesRenderer(renderer2);

    mRenderer.setInScroll(true);
  }
예제 #7
0
  // ========================================================================
  void drawPlotBoundaries(Canvas canvas, Rect frame, Paint hash_mark_label_paint) {
    if (mRenderer.isShowAxes()) {
      hash_mark_label_paint.setColor(mRenderer.getAxesColor());

      // Draw the bottom (horizontal) line
      canvas.drawLine(frame.left, frame.bottom, frame.right, frame.bottom, hash_mark_label_paint);

      // Draw the left (vertical) line
      canvas.drawLine(frame.left, frame.top, frame.left, frame.bottom, hash_mark_label_paint);

      // Optionally draw the right (vertical) line
      if (mRenderer.hasSecondaryYAxis())
        canvas.drawLine(frame.right, frame.top, frame.right, frame.bottom, hash_mark_label_paint);
    }
  }
예제 #8
0
  // ========================================================================
  float measurePrimaryYaxisTickLabels(Paint hash_mark_label_paint) {
    MinMax y_span = mRenderer.getYPrimaryAxisSpan();
    Rect text_bounds_holder = new Rect();

    List<Integer> y_label_widths = new ArrayList<Integer>();
    for (Double ylabel : MathHelper.getLabels(y_span, mRenderer.getYLabels())) {
      String y_label = getLabel(ylabel, Axis.Y_AXIS);
      hash_mark_label_paint.getTextBounds(y_label, 0, y_label.length(), text_bounds_holder);

      int label_width = text_bounds_holder.width();
      y_label_widths.add(label_width);
    }
    float max_label_width = Collections.max(y_label_widths);
    return max_label_width + VERTICAL_AXIS_LINE_LABEL_CLEARANCE;
  }
예제 #9
0
    public void setValues(long time, int dBm, String ssid) {
      if (time > 300) {
        timeStart = System.nanoTime();
        time = 0;
        series.clear();
      }

      XYSeriesRenderer renderer = new XYSeriesRenderer();
      renderer.setColor(Color.BLUE);
      renderer.setDisplayBoundingPoints(true);

      renderer.setLineWidth(1);
      renderer.setPointStyle(PointStyle.CIRCLE);
      renderer.setPointStrokeWidth(1);

      XYSeries xySerieseries;

      if (series.containsKey(SERIES_KEY)) {
        xySerieseries = series.get(SERIES_KEY);
        xySerieseries.add(time, dBm);
        series.remove(SERIES_KEY);
        series.put(SERIES_KEY, xySerieseries);
      } else {
        xySerieseries = new XYSeries(ssid);
        xySerieseries.add(time, dBm);
        series.put(SERIES_KEY, xySerieseries);
      }

      mDataset.addSeries(0, xySerieseries);
      mRenderer.addSeriesRenderer(0, renderer);
    }
  private void initChart() {
    // 初始化,必须保证XYMultipleSeriesDataset对象中的XYSeries数量和
    // XYMultipleSeriesRenderer对象中的XYSeriesRenderer数量一样多
    line1 = new XYSeries("折线1");
    line2 = new XYSeries("折线2");
    renderer1 = new XYSeriesRenderer();
    renderer2 = new XYSeriesRenderer();
    mDataset = new XYMultipleSeriesDataset();
    mXYMultipleSeriesRenderer = new XYMultipleSeriesRenderer();

    // 对XYSeries和XYSeriesRenderer的对象的参数赋值
    // initLine(line1);
    // initLine(line2);
    initRenderer(renderer1, Color.GREEN, PointStyle.CIRCLE, true);
    initRenderer(renderer2, Color.CYAN, PointStyle.TRIANGLE, true);

    // 将XYSeries对象和XYSeriesRenderer对象分别添加到XYMultipleSeriesDataset对象和XYMultipleSeriesRenderer对象中。
    mDataset.addSeries(line1);
    mDataset.addSeries(line2);
    mXYMultipleSeriesRenderer.addSeriesRenderer(renderer1);
    mXYMultipleSeriesRenderer.addSeriesRenderer(renderer2);

    // 配置chart参数
    setChartSettings(mXYMultipleSeriesRenderer, "X", "Y", 0, 10, 0, 100, Color.RED, Color.WHITE);

    // 通过该函数获取到一个View 对象
    chart = ChartFactory.getLineChartView(this, mDataset, mXYMultipleSeriesRenderer);

    // 将该View 对象添加到layout中。
    dynamic_chart_line_layout.addView(
        chart, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  }
예제 #11
0
  public LineGraph() {
    // Add single dataset to multiple dataset
    mDataset.addSeries(dataset);

    // Customization time for line 1!
    renderer.setColor(Color.WHITE);
    renderer.setPointStyle(PointStyle.SQUARE);
    renderer.setFillPoints(true);

    // Enable Zoom
    mRenderer.setZoomButtonsVisible(true);
    mRenderer.setXTitle("Day #");
    mRenderer.setYTitle("CM in Rainfall");

    // Add single renderer to multiple renderer
    mRenderer.addSeriesRenderer(renderer);
  }
예제 #12
0
  @Override
  protected void doForeGround() throws Exception {
    xValues.clear();
    yValues.clear();
    if (returnList != null) {
      Log.e(TAG, "returnList.size()=" + returnList.size());
      if (returnList.size() > 0) {
        getValues(returnList);
      } else {
        xValues.add(new double[] {1, 2, 3, 4, 5, 6});
        yValues.add(new double[] {0, 0, 0, 0, 0, 0});

        Log.e(TAG, "returnList.size()=0");
        ToastUtil.show(mContext, "无数据!");
        // return;
      }
    } else {

      xValues.add(new double[] {1, 2, 3, 4, 5, 6});
      yValues.add(new double[] {0, 0, 0, 0, 0, 0});

      Log.e(TAG, "returnList==null");
      ToastUtil.show(mContext, "网络连接异常!");
      // return;
    }
    double max = AppUtil.getMax(yValues);
    double xLimits = returnList.size();
    Log.d(TAG, "max=" + max);
    double maxPlus = max * 0.1;
    mRenderer.setYAxisMax(max + maxPlus);
    mRenderer.setPanLimits(new double[] {0, xLimits + 0.5, 0, mRenderer.getYAxisMax()});
    Log.e(TAG, "mRenderer.isClickEnabled()=" + mRenderer.isClickEnabled());
    initMultipleBar(xValues, yValues);
    Log.d(TAG, "mRenderer.getYAxisMax()=" + mRenderer.getYAxisMax());
    // mRenderer.setSelectableBuffer(35);
    // mRenderer.setClickEnabled(true);
    mChartView.repaint();
    mChartView.invalidate();
    /*
     * mChartView.setOnTouchListener(new OnTouchListener() {
     *
     * @Override public boolean onTouch(View v, MotionEvent event) { // TODO
     * Auto-generated method stub return false; } });
     */
  }
예제 #13
0
 /**
  * Checks the validity of the dataset and renderer parameters.
  *
  * @param dataset the multiple series dataset (cannot be null)
  * @param renderer the multiple series renderer (cannot be null)
  * @throws IllegalArgumentException if dataset is null or renderer is null or if the dataset and
  *     the renderer don't include the same number of series
  */
 private static void checkParameters(
     XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) {
   if (dataset == null
       || renderer == null
       || dataset.getSeriesCount() != renderer.getSeriesRendererCount()) {
     throw new IllegalArgumentException(
         "Dataset and renderer should be not null and should have the same number of series");
   }
 }
 private void setChartSettings(XYMultipleSeriesRenderer renderer) {
   renderer.setChartTitle("Chart demo");
   renderer.setXTitle("x values");
   renderer.setYTitle("y values");
   renderer.setXAxisMin(0.5);
   renderer.setXAxisMax(10.5);
   renderer.setYAxisMin(0);
   renderer.setYAxisMax(210);
 }
예제 #15
0
 @Override
 protected void onResume() {
   super.onResume();
   if (mChartView == null) {
     LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
     layout.setVisibility(View.INVISIBLE);
     mChartView = ChartFactory.getLineChartView(this, mDataset, mRenderer);
     // enable the chart click events
     mRenderer.setClickEnabled(true);
     mRenderer.setSelectableBuffer(10);
     mChartView.setOnClickListener(
         new View.OnClickListener() {
           public void onClick(View v) {}
         });
     layout.addView(
         mChartView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
   } else {
     mChartView.repaint();
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.observation_chart);

    if (!FileUtils.storageReady()) {
      showCustomToast(getString(R.string.error_storage));
      finish();
    }

    // TODO Check for invalid patient IDs
    String patientIdStr = getIntent().getStringExtra(Constants.KEY_PATIENT_ID);
    Integer patientId = Integer.valueOf(patientIdStr);
    mPatient = getPatient(patientId);

    mObservationFieldName = getIntent().getStringExtra(Constants.KEY_OBSERVATION_FIELD_NAME);

    setTitle(getString(R.string.app_name) + " > " + getString(R.string.view_observation));

    TextView textView = (TextView) findViewById(R.id.title_text);
    if (textView != null) {
      textView.setText(mObservationFieldName);
    }

    XYSeriesRenderer r = new XYSeriesRenderer();
    r.setLineWidth(3.0f);
    r.setColor(getResources().getColor(R.color.chart_red));
    r.setPointStyle(PointStyle.CIRCLE);
    r.setFillPoints(true);

    mRenderer.addSeriesRenderer(r);
    mRenderer.setShowLegend(false);
    // mRenderer.setXTitle("Encounter Date");
    // mRenderer.setAxisTitleTextSize(18.0f);
    mRenderer.setLabelsTextSize(11.0f);
    // mRenderer.setXLabels(10);
    mRenderer.setShowGrid(true);
    mRenderer.setLabelsColor(getResources().getColor(android.R.color.black));
  }
예제 #17
0
 /**
  * The graphical representation of a text, to handle both HORIZONTAL and VERTICAL orientations and
  * extra rotation angles.
  *
  * @param canvas the canvas to paint to
  * @param text the text to be rendered
  * @param x the X axis location of the text
  * @param y the Y axis location of the text
  * @param paint the paint to be used for drawing
  * @param extraAngle the array of points to be used for drawing the series
  */
 protected void drawText(
     Canvas canvas, String text, float x, float y, Paint paint, int extraAngle) {
   int angle = -mRenderer.getOrientation().getAngle() + extraAngle;
   if (angle != 0) {
     // canvas.scale(1 / mScale, mScale);
     canvas.rotate(angle, x, y);
   }
   canvas.drawText(text, x, y, paint);
   if (angle != 0) {
     canvas.rotate(-angle, x, y);
     // canvas.scale(mScale, 1 / mScale);
   }
 }
 public XYMultipleSeriesRenderer getBarDemoRenderer() {
   XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
   renderer.setAxisTitleTextSize(16);
   renderer.setChartTitleTextSize(20);
   renderer.setLabelsTextSize(15);
   renderer.setLegendTextSize(15);
   renderer.setMargins(new int[] {20, 30, 15, 0});
   SimpleSeriesRenderer r = new SimpleSeriesRenderer();
   r.setColor(Color.BLUE);
   renderer.addSeriesRenderer(r);
   r = new SimpleSeriesRenderer();
   r.setColor(Color.GREEN);
   renderer.addSeriesRenderer(r);
   return renderer;
 }
  private static XYChart prepareChart(
      final double minValue,
      final double maxValue,
      @NotNull final Generic expression,
      @NotNull final Constant variable) {
    final MyXYSeries realSeries =
        new MyXYSeries(getRealFunctionName(expression, variable), DEFAULT_NUMBER_OF_STEPS * 2);
    final MyXYSeries imagSeries =
        new MyXYSeries(getImagFunctionName(variable), DEFAULT_NUMBER_OF_STEPS * 2);

    boolean imagExists =
        PlotUtils.addXY(
            minValue,
            maxValue,
            expression,
            variable,
            realSeries,
            imagSeries,
            false,
            DEFAULT_NUMBER_OF_STEPS);

    final XYMultipleSeriesDataset data = new XYMultipleSeriesDataset();
    data.addSeries(realSeries);
    if (imagExists) {
      data.addSeries(imagSeries);
    }

    final XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
    renderer.setShowGrid(true);
    renderer.setXTitle(variable.getName());
    renderer.setYTitle("f(" + variable.getName() + ")");
    renderer.setChartTitleTextSize(20);

    renderer.setZoomEnabled(true);
    renderer.setZoomButtonsVisible(true);

    renderer.addSeriesRenderer(createCommonRenderer());
    if (imagExists) {
      renderer.addSeriesRenderer(createImagRenderer());
    }

    return new CubicLineChart(data, renderer, 0.1f);
  }
예제 #20
0
 /**
  * This has the same functionality as the super class of {@link Histogram}, except it calls
  * getDateLabel instead of just getLabel which will format the label as a date
  */
 public void drawXLabels(
     List<Double> xLabels,
     Double[] xTextLabelLocations,
     Canvas canvas,
     Paint paint,
     int left,
     int top,
     int bottom,
     double xPixelsPerUnit,
     double minX,
     double maxX) {
   XYMultipleSeriesRenderer renderer = mChart.getRenderer();
   int length = xLabels.size();
   boolean showLabels = renderer.isShowLabels();
   boolean showGrid = renderer.isShowGrid();
   for (int i = 0; i < length; i++) {
     double label = xLabels.get(i);
     float xLabel = (float) (left + xPixelsPerUnit * (label - minX));
     if (showLabels) {
       paint.setColor(renderer.getLabelsColor());
       canvas.drawLine(xLabel, bottom, xLabel, bottom + renderer.getLabelsTextSize() / 3, paint);
       mChart.drawText(
           canvas,
           getDateLabel(label),
           xLabel,
           bottom + renderer.getLabelsTextSize() * 4 / 3,
           paint,
           renderer.getXLabelsAngle());
     }
     if (showGrid) {
       paint.setColor(renderer.getGridColor());
       canvas.drawLine(xLabel, bottom, xLabel, top, paint);
     }
   }
   mChart.drawXTextLabels(
       xTextLabelLocations,
       canvas,
       paint,
       showLabels,
       left,
       top,
       bottom,
       xPixelsPerUnit,
       minX,
       maxX);
 }
예제 #21
0
 /**
  * Sets a few of the series renderer settings.
  *
  * @param renderer the renderer to set the properties to
  * @param title the chart title
  * @param xTitle the title for the X axis
  * @param yTitle the title for the Y axis
  * @param xMin the minimum value on the X axis
  * @param xMax the maximum value on the X axis
  * @param yMin the minimum value on the Y axis
  * @param yMax the maximum value on the Y axis
  * @param axesColor the axes color
  * @param labelsColor the labels color
  */
 public void setChartSettings(
     XYMultipleSeriesRenderer renderer,
     String title,
     String xTitle,
     String yTitle,
     double xMin,
     double xMax,
     double yMin,
     double yMax,
     int axesColor,
     int labelsColor) {
   renderer.setChartTitle(title);
   renderer.setXTitle(xTitle);
   renderer.setYTitle(yTitle);
   renderer.setXAxisMin(xMin);
   renderer.setXAxisMax(xMax);
   renderer.setYAxisMin(yMin);
   renderer.setYAxisMax(yMax);
   renderer.setAxesColor(axesColor);
   renderer.setLabelsColor(labelsColor);
 }
예제 #22
0
  // ========================================================================
  float measureXaxisTickLabels(Paint hash_mark_label_paint, MinMax x_span) {

    Rect text_bounds_holder = new Rect();

    List<Integer> x_label_heights = new ArrayList<Integer>();
    for (Double xlabel : MathHelper.getLabels(x_span, mRenderer.getXLabels())) {
      String x_label = getLabel(xlabel, Axis.X_AXIS);
      hash_mark_label_paint.getTextBounds(x_label, 0, x_label.length(), text_bounds_holder);

      int label_height = text_bounds_holder.height();
      x_label_heights.add(label_height);
    }
    float max_x_label_height = Collections.max(x_label_heights);
    return max_x_label_height
        + VERTICAL_AXIS_LINE_LABEL_CLEARANCE
        + DEFAULT_HORIZONTAL_AXIS_HASH_MARK_LENGTH;
  }
예제 #23
0
 public void setRenderer(XYMultipleSeriesRenderer renderer, int[] colors, PointStyle[] styles) {
   renderer.setAxisTitleTextSize(16);
   renderer.setChartTitleTextSize(20);
   renderer.setLabelsTextSize(15);
   renderer.setLegendTextSize(15);
   renderer.setPointSize(5f);
   renderer.setMargins(new int[] {20, 30, 15, 20});
   int length = colors.length;
   for (int i = 0; i < length; i++) {
     XYSeriesRenderer r = new XYSeriesRenderer();
     r.setColor(colors[i]);
     r.setPointStyle(styles[i]);
     renderer.addSeriesRenderer(r);
   }
 }
예제 #24
0
 /**
  * Builds a bar multiple series renderer to use the provided colors.
  *
  * @param colors the series renderers colors
  * @return the bar multiple series renderer
  */
 public XYMultipleSeriesRenderer buildBarRenderer(int[] colors) {
   XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
   renderer.setAxisTitleTextSize(16);
   renderer.setChartTitleTextSize(20);
   renderer.setLabelsTextSize(15);
   renderer.setLegendTextSize(15);
   int length = colors.length;
   for (int i = 0; i < length; i++) {
     SimpleSeriesRenderer r = new SimpleSeriesRenderer();
     r.setColor(colors[i]);
     renderer.addSeriesRenderer(r);
   }
   return renderer;
 }
  private void initView(View view) {
    // TODO Auto-generated method stub
    mLightView = (TextView) view.findViewById(R.id.info_light_data);

    XYSeries series = new XYSeries("");
    mDataset.addSeries(series);
    mCurrentSeries = series;
    XYSeriesRenderer renderer = new XYSeriesRenderer();
    mRenderer.addSeriesRenderer(renderer);
    renderer.setPointStyle(PointStyle.CIRCLE);
    renderer.setFillPoints(true);
    renderer.setDisplayChartValues(true);
    renderer.setDisplayChartValuesDistance(20);
    renderer.setChartValuesTextSize(15);
    mCurrentRenderer = renderer;

    // set data
    mCurrentSeries.clear();
    LinearLayout parentLayout = (LinearLayout) view.findViewById(R.id.chart_layout);
    mChartView = ChartFactory.getLineChartView(getActivity(), mDataset, mRenderer);
    parentLayout.addView(
        mChartView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  }
예제 #26
0
 /**
  * The graphical representation of the labels on the X axis.
  *
  * @param xLabels the X labels values
  * @param xTextLabelLocations the X text label locations
  * @param canvas the canvas to paint to
  * @param paint the paint to be used for drawing
  * @param left the left value of the labels area
  * @param top the top value of the labels area
  * @param bottom the bottom value of the labels area
  * @param xPixelsPerUnit the amount of pixels per one unit in the chart labels
  * @param minX the minimum value on the X axis in the chart
  */
 protected void drawXLabels(
     List<Double> xLabels,
     Double[] xTextLabelLocations,
     Canvas canvas,
     Paint paint,
     int left,
     int top,
     int bottom,
     double xPixelsPerUnit,
     double minX,
     float hash_mark_height,
     float max_text_height) {
   int length = xLabels.size();
   boolean showLabels = mRenderer.isShowLabels();
   for (int i = 0; i < length; i++) {
     double label = xLabels.get(i);
     float xLabel = (float) (left + xPixelsPerUnit * (label - minX));
     if (showLabels) {
       paint.setColor(mRenderer.getLabelsColor());
       canvas.drawLine(
           xLabel, bottom, xLabel, bottom + hash_mark_height, paint); // FIXME Magic numbers
       drawText(
           canvas,
           getLabel(label, Axis.X_AXIS),
           xLabel,
           bottom + hash_mark_height + max_text_height,
           paint,
           0);
     }
     if (mRenderer.isShowGrid() && mRenderer.isShowGridVerticalLines()) {
       paint.setColor(GRID_COLOR);
       canvas.drawLine(xLabel, bottom, xLabel, top, paint);
     }
   }
   if (showLabels) {
     paint.setColor(mRenderer.getLabelsColor());
     for (Double location : xTextLabelLocations) {
       float xLabel = (float) (left + xPixelsPerUnit * (location.doubleValue() - minX));
       canvas.drawLine(xLabel, bottom, xLabel, bottom + 4, paint); // FIXME Magic numbers
       drawText(canvas, mRenderer.getXTextLabel(location), xLabel, bottom + 12, paint, 0);
     }
   }
 }
예제 #27
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   SharedPreferences prefs = getSharedPreferences("theme", 0);
   switch (prefs.getInt("theme", 0)) {
     case 0:
       setTheme(R.style.AppTheme_Blue_Dark);
       break;
     case 1:
       setTheme(R.style.AppTheme_Blue_Light);
       break;
     case 2:
       setTheme(R.style.AppTheme_Green_Dark);
       break;
     case 3:
       setTheme(R.style.AppTheme_Green_Light);
       break;
     case 4:
       setTheme(R.style.AppTheme_Red_Dark);
       break;
     case 5:
       setTheme(R.style.AppTheme_Red_Light);
       break;
     case 6:
       setTheme(R.style.AppTheme_Orange_Dark);
       break;
     case 7:
       setTheme(R.style.AppTheme_Orange_Light);
       break;
     case 8:
       setTheme(R.style.AppTheme_Purple);
       break;
   }
   setContentView(R.layout.activity_graph);
   // set some properties on the maincal renderer
   mRenderer.setApplyBackgroundColor(true);
   mRenderer.setBackgroundColor(Color.BLACK);
   mRenderer.setAxisTitleTextSize(16);
   mRenderer.setChartTitleTextSize(0);
   mRenderer.setLabelsTextSize(15);
   mRenderer.setLegendTextSize(20);
   mRenderer.setLegendHeight(22);
   mRenderer.setPointSize(5f);
   mRenderer.setAxesColor(Color.BLACK);
   mRenderer.setXLabels(20);
   mRenderer.setYLabels(20);
   mRenderer.setPanEnabled(true);
   mRenderer.setZoomEnabled(true);
   mRenderer.setShowGrid(true);
   mRenderer.setXAxisBold(true);
   mRenderer.setYAxisBold(true);
   mRenderer.setZoomButtonsVisible(true);
   mRenderer.setZoomEnabled(true);
 }
예제 #28
0
  /**
   * Executes the chart demo.
   *
   * @param context the context
   * @return the built intent
   */
  public Intent execute(Context context, Child aChild) {
    Cursor c;
    List<double[]> x = new ArrayList<double[]>();
    List<double[]> values = new ArrayList<double[]>();
    SQLiteDatabase db = new DatabaseOpenHelper(context).getReadableDatabase();
    c =
        db.query(
            "bmichart", new String[] {"day", "P99", "P01", "P50"}, null, null, null, null, null);
    int factor = 5;

    double[] p99 = new double[(c.getCount() / factor) + 1];
    double[] p0 = new double[(c.getCount() / factor) + 1];
    double[] p50 = new double[(c.getCount() / factor) + 1];
    double[] days = new double[(c.getCount() / factor) + 1];
    double[] bmiData = new double[c.getCount() / factor + 1];
    c.moveToFirst();
    int i = 0;
    int temp;
    do {
      if (i % factor == 0) {
        temp = i / factor;
        p99[temp] = c.getDouble(1);
        p0[temp] = c.getDouble(2);
        p50[temp] = c.getDouble(3);
        days[temp] = i;
      }
      i++;
    } while (c.moveToNext());
    c.close();

    // initializing height to -5
    for (i = 0; i < bmiData.length; i++) {
      bmiData[i] = -5;
    }
    c =
        db.query(
            aChild.getDataTableName(), new String[] {"day", "bmi"}, null, null, null, null, null);

    i = 0;
    String[] titles = new String[] {"P99", "P0", "P50", "BMI"};
    int[] colors = new int[] {Color.CYAN, Color.GREEN, Color.RED, Color.BLUE};
    PointStyle[] styles =
        new PointStyle[] {PointStyle.POINT, PointStyle.POINT, PointStyle.POINT, PointStyle.CIRCLE};
    if (c.moveToFirst()) {
      do {
        temp = (int) (c.getDouble(0) / factor);
        bmiData[temp] = c.getDouble(1);
        i++;
      } while (c.moveToNext());
      values.add(bmiData);
    } else {
      titles = new String[] {"P99", "P0", "P50"};
      colors = new int[] {Color.CYAN, Color.GREEN, Color.RED};
      styles = new PointStyle[] {PointStyle.POINT, PointStyle.POINT, PointStyle.POINT};
    }
    for (int v = 0; v < titles.length; v++) {
      x.add(days);
    }
    values.add(p99);
    values.add(p0);
    values.add(p50);

    XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);

    int length = renderer.getSeriesRendererCount();
    for (i = 0; i < length; i++) {
      ((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
    }

    setChartSettings(
        renderer, "BMI Day Chart", "Days", "BMI", 0, 1000, 0, 125, Color.LTGRAY, Color.LTGRAY);
    renderer.setXLabels(12);
    renderer.setYLabels(10);
    renderer.setShowGrid(true);
    renderer.setXLabelsAlign(Align.RIGHT);
    renderer.setYLabelsAlign(Align.RIGHT);
    renderer.setZoomButtonsVisible(true);
    renderer.setPanLimits(new double[] {-10, 20, -10, 40});
    renderer.setZoomLimits(new double[] {-10, 20, -10, 40});
    Intent intent =
        ChartFactory.getLineChartIntent(
            context, buildDataset(titles, x, values), renderer, aChild.getName());
    c.close();
    db.close();
    return intent;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    mDataCache = DataCache.getInstance();

    mDataset = new XYMultipleSeriesDataset();
    mRenderer = new XYMultipleSeriesRenderer();
    // Renderer
    // Basic
    mRenderer.setMargins(new int[] {100, 150, 30, 100});
    mRenderer.setChartTitleTextSize(20);
    mRenderer.setApplyBackgroundColor(true);
    mRenderer.setBackgroundColor(0xffE8E8E7);
    mRenderer.setMarginsColor(0xffE8E8E7);
    mRenderer.setLegendTextSize(15);
    mRenderer.setPointSize(5);
    mRenderer.setShowLegend(true);
    mRenderer.setClickEnabled(false);
    // Axes
    mRenderer.setAxisTitleTextSize(50);
    mRenderer.setBarSpacing(50);
    mRenderer.setYTitle("Light");
    // mRenderer.setAxesColor(Color.BLACK);
    // Labels
    // mRenderer.setLabelsColor(Color.WHITE);
    mRenderer.setLabelsTextSize(35);
    mRenderer.setXLabels(0);
    mRenderer.setYLabels(10);
    mRenderer.setYAxisMin(0);
    mRenderer.setYAxisMax(1000);
    mRenderer.setXLabelsColor(Color.BLACK);
    mRenderer.setYLabelsColor(0, Color.BLACK);
    mRenderer.setXLabelsAngle(-45f);
    mRenderer.setXLabelsAlign(Align.CENTER);
    mRenderer.setYLabelsAlign(Align.RIGHT);

    mRenderer.setPanEnabled(false, false);
    mRenderer.setZoomEnabled(false, false);
  }
예제 #30
0
  /** Called when the fragment is first created. */
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ScrollView view = (ScrollView) inflater.inflate(R.layout.clima, container, false);

    context = getActivity();
    ((MainActivity) context).setFooter(R.id.footer_sensor);

    RelativeLayout row1 = (RelativeLayout) view.findViewById(R.id.temp);
    RelativeLayout row2 = (RelativeLayout) view.findViewById(R.id.humi);
    RelativeLayout row3 = (RelativeLayout) view.findViewById(R.id.baro);

    Animation animation = AnimationUtils.loadAnimation(context, R.anim.push_top_in);
    row1.startAnimation(animation);
    row2.startAnimation(animation);
    row3.startAnimation(animation);

    humidity = (TextView) view.findViewById(R.id.humidity);
    barometric = (TextView) view.findViewById(R.id.barometric);
    temperature = (TextView) view.findViewById(R.id.temperature);

    app = (Node) context.getApplication();
    sensor = app.getSensor();

    // Tempurature
    LinearLayout chart1 = (LinearLayout) view.findViewById(R.id.chart1);

    tempRenderer = Node.getGraphStyle(tempRenderer, context);

    tempChartView = ChartFactory.getLineChartView(context, tempDataset, tempRenderer);

    chart1.addView(
        tempChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    tempChartView.repaint();

    tempSeries = new XYSeries("temp");
    tempDataset.addSeries(tempSeries);
    XYSeriesRenderer renderer1 = new XYSeriesRenderer();
    tempRenderer.addSeriesRenderer(renderer1);
    // renderer.setPointStyle(PointStyle.CIRCLE);
    // renderer.setFillPoints(true);
    renderer1.setLineWidth(4);
    renderer1.setColor(Color.RED);

    tempArray = new ArrayList<Double>();

    // Humidity
    LinearLayout chart2 = (LinearLayout) view.findViewById(R.id.chart2);

    humiRenderer = Node.getGraphStyle(humiRenderer, context);

    humiChartView = ChartFactory.getLineChartView(context, humiDataset, humiRenderer);

    chart2.addView(
        humiChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    humiChartView.repaint();

    humiSeries = new XYSeries("humi");
    humiDataset.addSeries(humiSeries);
    XYSeriesRenderer renderer2 = new XYSeriesRenderer();
    humiRenderer.addSeriesRenderer(renderer2);
    // renderer.setPointStyle(PointStyle.CIRCLE);
    // renderer.setFillPoints(true);
    renderer2.setLineWidth(4);
    renderer2.setColor(Color.RED);

    humiArray = new ArrayList<Double>();

    // Pressure
    LinearLayout chart3 = (LinearLayout) view.findViewById(R.id.chart3);

    presRenderer = Node.getGraphStyle(presRenderer, context);

    presChartView = ChartFactory.getLineChartView(context, presDataset, presRenderer);

    chart3.addView(
        presChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    presChartView.repaint();

    presSeries = new XYSeries("pres");
    presDataset.addSeries(presSeries);
    XYSeriesRenderer renderer3 = new XYSeriesRenderer();
    presRenderer.addSeriesRenderer(renderer3);
    // renderer.setPointStyle(PointStyle.CIRCLE);
    // renderer.setFillPoints(true);
    renderer3.setLineWidth(4);
    renderer3.setColor(Color.RED);

    presArray = new ArrayList<Double>();

    return view;
  }