protected void setChartSettings(
     XYMultipleSeriesRenderer mXYMultipleSeriesRenderer,
     String xTitle,
     String yTitle,
     double xMin,
     double xMax,
     double yMin,
     double yMax,
     int axesColor,
     int labelsColor) {
   // 有关对图表的渲染可参看api文档
   mXYMultipleSeriesRenderer.setChartTitle(title);
   mXYMultipleSeriesRenderer.setXTitle(xTitle);
   mXYMultipleSeriesRenderer.setYTitle(yTitle);
   mXYMultipleSeriesRenderer.setXAxisMin(xMin);
   mXYMultipleSeriesRenderer.setAxisTitleTextSize(30);
   mXYMultipleSeriesRenderer.setChartTitleTextSize(50);
   mXYMultipleSeriesRenderer.setLabelsTextSize(15);
   mXYMultipleSeriesRenderer.setXAxisMax(xMax);
   mXYMultipleSeriesRenderer.setYAxisMin(yMin);
   mXYMultipleSeriesRenderer.setYAxisMax(yMax);
   mXYMultipleSeriesRenderer.setAxesColor(axesColor);
   mXYMultipleSeriesRenderer.setLabelsColor(labelsColor);
   mXYMultipleSeriesRenderer.setShowGrid(true);
   mXYMultipleSeriesRenderer.setGridColor(Color.GRAY);
   mXYMultipleSeriesRenderer.setXLabels(20);
   mXYMultipleSeriesRenderer.setYLabels(10);
   mXYMultipleSeriesRenderer.setXTitle("time");
   mXYMultipleSeriesRenderer.setYLabelsAlign(Align.RIGHT);
   mXYMultipleSeriesRenderer.setPointSize((float) 5);
   mXYMultipleSeriesRenderer.setShowLegend(true);
   mXYMultipleSeriesRenderer.setLegendTextSize(20);
 }
 @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);
 }
 public void init() {
   mRenderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00)); // transparent margins
   mRenderer.setPanEnabled(false, false);
   mRenderer.setYAxisMax(-40);
   mRenderer.setYAxisMin(-100);
   mRenderer.setYLabels(3);
   mRenderer.setYTitle(LABEL_Y);
   mRenderer.setXAxisMin(0);
   mRenderer.setXAxisMax(300);
   mRenderer.setXLabels(15);
   mRenderer.setXTitle(LABEL_X);
   mRenderer.setShowGrid(true);
   mRenderer.setShowLabels(true);
   mRenderer.setShowLegend(false);
   mRenderer.setShowCustomTextGrid(true);
 }
  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);
  }
Example #5
0
  protected void setRenderer(XYMultipleSeriesRenderer renderer, int[] colors, PointStyle[] styles) {
    renderer.setAxisTitleTextSize(16);
    renderer.setChartTitleTextSize(20);
    renderer.setLabelsTextSize(15);
    renderer.setLegendTextSize(15);
    renderer.setPointSize(5f);
    renderer.setYLabels(5);
    renderer.setMargins(new int[] {30, 15, 30, 15});
    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);
    }
    renderer.setClickEnabled(true);
    renderer.setSelectableBuffer(100);
    renderer.setApplyBackgroundColor(true);
    renderer.setBackgroundColor(Color.argb(100, 50, 50, 50));

    renderer.setAxesColor(Color.LTGRAY);
    renderer.setZoomButtonsVisible(true);
    renderer.setPointSize(10);

    renderer.setChartTitle("Fuel Efficiency and Cost");
    // mRenderer.setXTitle("Date");

    renderer.setShowGrid(true);
    renderer.setXLabelsAlign(Align.RIGHT);
    renderer.setYLabelsAlign(Align.LEFT);

    renderer.setYTitle(cunits, 0);

    renderer.setLabelsColor(Color.WHITE);
    renderer.setXLabelsColor(Color.GREEN);
    renderer.setYLabelsColor(0, colors[0]);
    renderer.setYLabelsColor(1, colors[1]);

    renderer.setYTitle(dunits, 1);
    renderer.setYAxisAlign(Align.RIGHT, 1);
    renderer.setYLabelsAlign(Align.RIGHT, 1);
  }
  protected void setChartSettings(XYMultipleSeriesRenderer renderer) {
    double xMin, xMax, yMin = 5, yMax = 40;

    // 有关对图表的渲染可参看api文档
    renderer.setAxisTitleTextSize(16);
    renderer.setChartTitleTextSize(16);
    renderer.setLabelsTextSize(15);
    renderer.setLegendTextSize(15);

    renderer.setXTitle("时间 (月/日 时:分)");
    renderer.setYTitle("温度 (摄氏度)");
    renderer.setChartTitle(title);

    // XY轴的最大/最小值
    // renderer.setXAxisMin(xMin);
    // renderer.setXAxisMax(xMax);
    renderer.setYAxisMin(yMin);
    renderer.setYAxisMax(yMax);

    // 坐标轴颜色
    renderer.setAxesColor(Color.RED);
    // 标签(title、单位)颜色
    renderer.setLabelsColor(Color.WHITE);
    // 网格属性
    renderer.setShowGrid(true);
    renderer.setGridColor(Color.BLACK);
    // 背景色 不起作用
    // renderer.setBackgroundColor(Color.WHITE);

    // 横纵坐标格数
    renderer.setXLabels(5);
    renderer.setYLabels((int) ((yMax - yMin) / 5));
    // Y轴的刻度到Y轴的右边
    renderer.setYLabelsAlign(Align.RIGHT);
    // 折线转折点大小
    renderer.setPointSize((float) 7);
    // 是否显示图例
    renderer.setShowLegend(false);
    // 显示折线转折点值
    // renderer.setDisplayChartValues(true);
  }
  @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));
  }
  /**
   * 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;
  }
  /**
   * Executes the chart demo.
   *
   * @param context the context
   * @return the built intent
   */
  public Intent execute(Context context) {
    String[] titles = new String[] {"Crete Air Temperature", "Skiathos Air Temperature"};
    List<double[]> x = new ArrayList<double[]>();
    for (int i = 0; i < titles.length; i++) {
      x.add(new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
    }
    List<double[]> values = new ArrayList<double[]>();
    values.add(
        new double[] {12.3, 12.5, 13.8, 16.8, 20.4, 24.4, 26.4, 26.1, 23.6, 20.3, 17.2, 13.9});
    values.add(new double[] {9, 10, 11, 15, 19, 23, 26, 25, 22, 18, 13, 10});
    int[] colors = new int[] {Color.GREEN, Color.rgb(200, 150, 0)};
    PointStyle[] styles = new PointStyle[] {PointStyle.CIRCLE, PointStyle.DIAMOND};
    XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
    renderer.setPointSize(5.5f);
    int length = renderer.getSeriesRendererCount();

    for (int i = 0; i < length; i++) {
      XYSeriesRenderer r = (XYSeriesRenderer) renderer.getSeriesRendererAt(i);
      r.setLineWidth(5);
      r.setFillPoints(true);
    }
    setChartSettings(
        renderer,
        "Weather data",
        "Month",
        "Temperature",
        0.5,
        12.5,
        0,
        40,
        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});

    XYValueSeries sunSeries = new XYValueSeries("Sunshine hours");
    sunSeries.add(1, 35, 4.3);
    sunSeries.add(2, 35, 4.9);
    sunSeries.add(3, 35, 5.9);
    sunSeries.add(4, 35, 8.8);
    sunSeries.add(5, 35, 10.8);
    sunSeries.add(6, 35, 11.9);
    sunSeries.add(7, 35, 13.6);
    sunSeries.add(8, 35, 12.8);
    sunSeries.add(9, 35, 11.4);
    sunSeries.add(10, 35, 9.5);
    sunSeries.add(11, 35, 7.5);
    sunSeries.add(12, 35, 5.5);
    XYSeriesRenderer lightRenderer = new XYSeriesRenderer();
    lightRenderer.setColor(Color.YELLOW);

    XYSeries waterSeries = new XYSeries("Water Temperature");
    waterSeries.add(1, 16);
    waterSeries.add(2, 15);
    waterSeries.add(3, 16);
    waterSeries.add(4, 17);
    waterSeries.add(5, 20);
    waterSeries.add(6, 23);
    waterSeries.add(7, 25);
    waterSeries.add(8, 25.5);
    waterSeries.add(9, 26.5);
    waterSeries.add(10, 24);
    waterSeries.add(11, 22);
    waterSeries.add(12, 18);
    renderer.setBarSpacing(0.5);
    XYSeriesRenderer waterRenderer = new XYSeriesRenderer();
    waterRenderer.setColor(Color.argb(250, 0, 210, 250));

    XYMultipleSeriesDataset dataset = buildDataset(titles, x, values);
    dataset.addSeries(0, sunSeries);
    dataset.addSeries(0, waterSeries);
    renderer.addSeriesRenderer(0, lightRenderer);
    renderer.addSeriesRenderer(0, waterRenderer);
    waterRenderer.setDisplayChartValues(true);
    waterRenderer.setChartValuesTextSize(10);

    String[] types =
        new String[] {BarChart.TYPE, BubbleChart.TYPE, LineChart.TYPE, CubicLineChart.TYPE};
    Intent intent =
        ChartFactory.getCombinedXYChartIntent(
            context, dataset, renderer, types, "Weather parameters");
    return intent;
  }
Example #10
0
  public void drawHRLayout(double[] myHRs, Date[] myDates) {
    String[] titles = new String[] {"FitFormula User"};
    List<Date[]> dates = new ArrayList<Date[]>();
    List<double[]> values = new ArrayList<double[]>();
    for (int i = 0; i < titles.length; i++) {
      dates.add(myDates);
      values.add(myHRs);
    }

    int[] colors = new int[] {Color.YELLOW};
    PointStyle[] styles = new PointStyle[] {PointStyle.CIRCLE};
    XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
    int length = renderer.getSeriesRendererCount();
    for (int i = 0; i < length; i++) {
      ((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
    }
    double hrMin = getMinValue(myHRs);
    double hrMax = getMaxValue(myHRs);
    setChartSettings(
        renderer,
        "Resting Heart Rate",
        "Date",
        "BPM",
        dates.get(0)[0].getTime(),
        dates.get(0)[myDates.length - 1].getTime(),
        hrMin - hrMin * 0.20,
        hrMax + hrMax * 0.20,
        Color.LTGRAY,
        Color.LTGRAY);
    renderer.setXLabels(myDates.length - 1);
    renderer.setYLabels(8);
    renderer.setShowGrid(true);
    renderer.setXLabelsAlign(Align.RIGHT);
    renderer.setYLabelsAlign(Align.RIGHT);
    renderer.setZoomButtonsVisible(false);
    renderer.setZoomEnabled(false, false);
    renderer.setPanEnabled(true, false);
    renderer.setPanLimits(new double[] {0, myDates.length - 1, 0, hrMax}); // minX, maxX, minY, maxY
    // renderer.setZoomLimits(new double[] { 0, 20, 60, 120 });

    mRelative.removeAllViews();

    titleText.setText(
        Html.fromHtml("<br><b><u><big>My Resting Heart Rate History</big></u></b><br>"));
    titleText.setId(1);
    RelativeLayout.LayoutParams relParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    relParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    relParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    mRelative.addView(titleText, relParams);

    // Add the view!
    chartView =
        ChartFactory.getTimeChartView(
            context, buildDateDataset(titles, dates, values), renderer, "MM/dd/yyyy");
    chartView.setId(2);
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int height = displaymetrics.heightPixels;
    int width = displaymetrics.widthPixels;
    int chartSize = (int) (width * 0.9);
    relParams = new RelativeLayout.LayoutParams(width, chartSize);
    relParams.addRule(RelativeLayout.BELOW, titleText.getId());
    relParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    mRelative.addView(chartView, relParams);

    hrButton = new Button(this);
    hrButton.setId(3);
    hrButton.setText("Measure Resting Heart Rate");
    // hrButton.setWidth(width);
    hrButton.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            Intent i = new Intent(HcHeartRate.this, FitTestHR.class);
            i.putExtra("nextactivity", "HcHeartRate"); // Telling HR Class what is next activity
            getParent().startActivityForResult(i, HCHEARTRATE_REQUEST_CODE);
          }
        });
    relParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    relParams.addRule(RelativeLayout.BELOW, chartView.getId());
    relParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    mRelative.addView(hrButton, relParams);
  }
Example #11
0
  public static View genBarChart(final Activity activity, final BarChartData data) {
    if (data == null || data.getData() == null) return null;
    Resources resources = activity.getResources();
    final String[] axis_x_string = resources.getStringArray(R.array.week);
    final XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
    XYMultipleSeriesDataset dataSet = new XYMultipleSeriesDataset();
    renderer.setApplyBackgroundColor(true);
    renderer.setBackgroundColor(Color.WHITE);
    renderer.setMarginsColor(Color.WHITE);
    renderer.setTextTypeface(null, Typeface.NORMAL);

    renderer.setShowGrid(true);
    renderer.setGridColor(resources.getColor(R.color.gray3));

    renderer.setLabelsColor(Color.BLACK);
    renderer.setAxesColor(resources.getColor(R.color.gray1));
    renderer.setBarSpacing(0.5);

    renderer.setXTitle("");
    renderer.setYTitle("");
    renderer.setXLabelsColor(Color.BLACK);
    renderer.setLabelsTextSize(
        activity.getResources().getDimensionPixelSize(R.dimen.ov_statistics_axis_text_size));
    renderer.setYLabelsColor(0, Color.BLACK);
    renderer.setXLabelsPadding(resources.getDimension(R.dimen.ov_statistics_x_axis_padding));
    renderer.setYLabelsPadding(resources.getDimension(R.dimen.ov_statistics_x_axis_padding));
    renderer.setXLabelsAlign(Paint.Align.CENTER);
    renderer.setYLabelsAlign(Paint.Align.CENTER);
    renderer.setXLabelsAngle(0);
    renderer.setShowTickMarks(false);

    renderer.setXLabels(0);
    renderer.setYAxisMin(0);

    for (int i = 0; i < data.getData().length; i++) {
      final XYSeries series = new XYSeries("");
      dataSet.addSeries(series);
      XYSeriesRenderer yRenderer = new XYSeriesRenderer();
      renderer.addSeriesRenderer(yRenderer);
      yRenderer.setColor(resources.getColor(data.sColorId[i]));
      series.add(0, 0);
      renderer.addXTextLabel(0, "");
      for (int j = 0; j < data.getData()[i].length; j++) {
        renderer.addXTextLabel(j + 1, axis_x_string[j]);
        series.add(j + 1, ((float) data.getData()[i][j]) / 3600000);
      }
      series.add(data.getData()[i].length + 1, 0);
      renderer.addXTextLabel(data.getData()[i].length + 1, "");
    }

    renderer.setZoomEnabled(false);
    renderer.setZoomEnabled(false, false);
    renderer.setClickEnabled(true);
    renderer.setPanEnabled(false);
    renderer.setShowLegend(false);
    try {
      renderer.setDrawGridAfterBar(true);
      renderer.setHighLightRectEnabled(true);
      renderer.setHighLightRectStrokeWidth(
          activity
              .getResources()
              .getDimensionPixelOffset(R.dimen.ov_statistics_highlight_stroke_width));
      renderer.setHighLightRectStrokeColor(activity.getResources().getColor(R.color.gray3));
    } catch (NoSuchMethodError e) {
      e.printStackTrace();
    }
    View view = ChartFactory.getBarChartView(activity, dataSet, renderer, BarChart.Type.DEFAULT);
    view.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (!(v instanceof GraphicalView)) return;
            final GraphicalView view = (GraphicalView) v;
            SeriesSelection selection = view.getCurrentSeriesAndPoint();
            try {
              view.onClick(selection);
            } catch (NoSuchMethodError e) {
              e.printStackTrace();
            }
            if (selection == null) return;
            int idx = selection.getPointIndex() - 1;
            View popupView = activity.getLayoutInflater().inflate(R.layout.bar_chart_popup, null);
            if (data.from.equals(CaseOverviewFragment.class.getSimpleName())
                || data.from.equals(EquipmentOverviewFragment.class.getSimpleName())) {
              ((TextView) popupView.findViewById(R.id.date)).setText(data.getDate()[idx]);
              if (data.getData()[0][idx] >= 0) {
                int hour = (int) data.getData()[0][idx] / 3600000;
                int min = (int) ((data.getData()[0][idx] % 3600000)) / 60000;
                ((TextView) popupView.findViewById(R.id.working_time))
                    .setText(
                        activity.getResources().getString(R.string.statistics_popup_time_finish)
                            + " "
                            + (hour < 10 ? ("0" + hour) : hour)
                            + " : "
                            + (min < 10 ? ("0" + min) : min));
              } else {
                popupView.findViewById(R.id.vg_working_time).setVisibility(View.GONE);
              }
              popupView.findViewById(R.id.vg_overtime).setVisibility(View.GONE);
            } else if (data.from.equals(WorkerOverviewFragment.class.getSimpleName())) {
              ((TextView) popupView.findViewById(R.id.date)).setText(data.getDate()[idx]);
              if (data.getData()[0][idx] >= 0) {
                int hour = (int) data.getData()[0][idx] / 3600000;
                int min = (int) ((data.getData()[0][idx] % 3600000)) / 60000;
                ((TextView) popupView.findViewById(R.id.working_time))
                    .setText(
                        activity.getResources().getString(R.string.statistics_popup_time_work)
                            + " "
                            + (hour < 10 ? ("0" + hour) : hour)
                            + " : "
                            + (min < 10 ? ("0" + min) : min));
              } else {
                popupView.findViewById(R.id.vg_working_time).setVisibility(View.GONE);
              }
              if (data.getData()[1][idx] >= 0) {
                int hour = (int) data.getData()[1][idx] / 3600000;
                int min = (int) ((data.getData()[1][idx] % 3600000)) / 60000;
                ((TextView) popupView.findViewById(R.id.overtime))
                    .setText(
                        activity.getResources().getString(R.string.statistics_popup_time_overtime)
                            + " "
                            + (hour < 10 ? ("0" + hour) : hour)
                            + " : "
                            + (min < 10 ? ("0" + min) : min));
              } else {
                popupView.findViewById(R.id.vg_overtime).setVisibility(View.GONE);
              }
            }
            final PopupWindow popup =
                new PopupWindow(
                    popupView,
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            popup.setBackgroundDrawable(new BitmapDrawable());
            popup.setOutsideTouchable(true);
            popup.setOnDismissListener(
                new PopupWindow.OnDismissListener() {
                  @Override
                  public void onDismiss() {
                    try {
                      view.onClick(null);
                    } catch (NoSuchMethodError e) {
                      e.printStackTrace();
                    }
                  }
                });
            /* calculate popup position */
            popupView.measure(
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            int[] dateChooserLocations = new int[2];
            (activity.findViewById(R.id.ov_statistics_week_chooser))
                .getLocationOnScreen(dateChooserLocations);
            int[] statisticsViewLocations = new int[2];
            v.getLocationOnScreen(statisticsViewLocations);
            int[] barChartLocations = new int[2];
            v.getLocationOnScreen(barChartLocations);
            int x_pos =
                barChartLocations[0]
                    + (int) ((XYChart) view.getChart()).getXAxisPos((double) (idx + 1))
                    - popupView.getMeasuredWidth() / 2;
            int y_base =
                dateChooserLocations[1]
                    + (activity.findViewById(R.id.ov_statistics_week_chooser)).getMeasuredHeight();
            int y_pos =
                (statisticsViewLocations[1] - y_base) / 2
                    + y_base
                    - popupView.getMeasuredHeight() / 2;
            popup.showAtLocation(v, Gravity.NO_GRAVITY, x_pos, y_pos);
          }
        });
    return view;
  }
  public void AChart() {
    //		mDataset = new XYMultipleSeriesDataset();
    //		mRenderer = new XYMultipleSeriesRenderer();
    //		mCurrentRenderer = new XYSeriesRenderer();

    mRenderer.setApplyBackgroundColor(true); // 设置是否显示背景色
    mRenderer.setBackgroundColor(Color.argb(50, 214, 241, 255)); // 设置背景色

    mRenderer.setAxisTitleTextSize(32); // 设置轴标题文字的大小
    mRenderer.setAxesColor(Color.BLACK); // 坐标轴颜色

    mRenderer.setChartTitleTextSize(32); // ?设置整个图表标题文字大小
    mRenderer.setChartTitle(appState.userID);

    mRenderer.setXLabelsColor(Color.BLACK); // 设置X轴刻度颜色
    mRenderer.setYLabelsColor(0, Color.BLACK); // 设置Y轴刻度颜色	
    mRenderer.setLabelsTextSize(32); // 设置刻度显示文字的大小(XY轴都会被设置)

    mRenderer.setLegendTextSize(32); // 图例文字大小

    mRenderer.setMargins(new int[] {30, 30, 50, 10}); // 设置图表的外边框(上/左/下/右)
    mRenderer.setMarginsColor(Color.argb(50, 214, 241, 255)); // 边框颜色

    mRenderer.setZoomButtonsVisible(false); // 是否显示放大缩小按钮

    mRenderer.setShowGrid(true); // 显示网格

    mRenderer.setPointSize(10); // 设置点的大小(图上显示的点的大小和图例中点的大小都会被设置)

    String seriesTitle = "I-Sleep";

    if (mDataset.getSeriesCount() > 0) {
      mDataset.removeSeries(0);
      mRenderer.removeAllRenderers();
    }

    XYSeries series = new XYSeries(seriesTitle); // 定义XYSeries
    mDataset.addSeries(series); // 在XYMultipleSeriesDataset中添加XYSeries
    mCurrentSeries = series; // 设置当前需要操作的XYSeries  \	

    addPoint();

    XYSeriesRenderer renderer = new XYSeriesRenderer(); // 定义XYSeriesRenderer
    mRenderer.addSeriesRenderer(renderer); // 将单个XYSeriesRenderer增加到XYMultipleSeriesRenderer
    renderer.setPointStyle(PointStyle.CIRCLE); // 点的类型是圆形
    renderer.setFillPoints(true); // 设置点是否实心
    renderer.setColor(Color.BLUE); // 折线颜色

    mCurrentRenderer = renderer;

    //	    if (mChartView == null) {
    if (layout != null) {
      layout.removeAllViews();
    }
    layout = (LinearLayout) getActivity().findViewById(R.id.chart);
    mChartView =
        ChartFactory.getLineChartView(getActivity().getApplicationContext(), mDataset, mRenderer);
    mRenderer.setClickEnabled(true); // 设置图表是否允许点击
    mRenderer.setSelectableBuffer(100); // 设置点的缓冲半径值(在某点附件点击时,多大范围内都算点击这个点)
    mChartView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // 这段代码处理点击一个点后,获得所点击的点在哪个序列中以及点的坐标.
            // -->start
            SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
            double[] xy = mChartView.toRealPoint(0);
            if (seriesSelection == null) {
              //	              Toast.makeText(getActivity().getApplicationContext(), "No chart
              // element was clicked", Toast.LENGTH_SHORT).show();
            } else {
              //	              Toast.makeText(getActivity().getApplicationContext(),
              //	                  "Chart element in series index " +
              // seriesSelection.getSeriesIndex()
              //	                      + " data point index " + seriesSelection.getPointIndex() + "
              // was clicked"
              //	                      + " closest point value X=" + seriesSelection.getXValue() +
              // ", Y=" + seriesSelection.getValue()
              //	                      + " clicked point value X=" + (float) xy[0] + ", Y=" +
              // (float) xy[1], Toast.LENGTH_SHORT).show();

              //	              tv_graphdata.setText("X = " +
              // String.valueOf(seriesSelection.getXValue()) +
              //	            		  " Y = " + String.valueOf(seriesSelection.getValue()));
              tv_graphdata.setText(
                  appState.userID
                      + "  "
                      + appState.userName
                      + "  "
                      + "Duration:"
                      + duration[(int) seriesSelection.getXValue() - 1]
                      + "hours\n"
                      + "Starttime:"
                      + starttime[(int) seriesSelection.getXValue() - 1]
                      + "\n"
                      + "Endtime:"
                      + endtime[(int) seriesSelection.getXValue() - 1]);
              tv_graphdata.setTextSize(16);

              // 播放音频
              if (!"".equals(recfile[(int) seriesSelection.getXValue() - 1])) {
                playRecWithSysPlayer(recfile[(int) seriesSelection.getXValue() - 1]);
              } else {
                Toast.makeText(getActivity(), "There's no record.", Toast.LENGTH_LONG).show();
              }
            }
            // -->end
          }
        });
    mChartView.setOnLongClickListener(
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
            if (seriesSelection == null) {
              //	              Toast.makeText(XYChartBuilder.this, "No chart element was long
              // pressed",Toast.LENGTH_SHORT);
              return false; // no chart element was long pressed, so let something
              // else handle the event
            } else {
              //	              Toast.makeText(XYChartBuilder.this, "Chart element in series index "
              //	                  + seriesSelection.getSeriesIndex() + " data point index "
              //	                  + seriesSelection.getPointIndex() + " was long pressed",
              // Toast.LENGTH_SHORT);
              return true; // the element was long pressed - the event has been
              // handled
            }
          }
        });
    // 这段代码处理放大缩小
    // -->start
    mChartView.addZoomListener(
        new ZoomListener() {
          public void zoomApplied(ZoomEvent e) {
            String type = "out";
            if (e.isZoomIn()) {
              type = "in";
            }
            System.out.println("Zoom " + type + " rate " + e.getZoomRate());
          }

          public void zoomReset() {
            System.out.println("Reset");
          }
        },
        true,
        true);
    // -->end
    // 设置拖动图表时后台打印出图表坐标的最大最小值.
    mChartView.addPanListener(
        new PanListener() {
          public void panApplied() {
            System.out.println(
                "New X range=["
                    + mRenderer.getXAxisMin()
                    + ", "
                    + mRenderer.getXAxisMax()
                    + "], Y range=["
                    + mRenderer.getYAxisMax()
                    + ", "
                    + mRenderer.getYAxisMax()
                    + "]");
          }
        });
    layout.addView(
        mChartView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    boolean enabled = mDataset.getSeriesCount() > 0;
    //	      } else {
    //	        mChartView.repaint();
    //	      }
  }
  // the zephry manager will send RR values to this listener.
  // RRs are the milliseconds between beats.  Example, steady 60 BPM heartbeat sends rr values of
  // 1000 because there is a full second between beats
  public void updateChart(int rr) {

    // we throw out any 0s or absurd values.  We have found this tends not to happen with a good
    // chest strap
    if ((rr < 1) || (rr > 3000)) return;
    int pulserate = 60000 / rr;
    series.add(x, pulserate);
    x = x + rr; // time is also the accumulation of RR values

    // Achartengine stuff
    XYSeriesRenderer renderer = new XYSeriesRenderer();
    XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();

    // Set the right side to current time
    mRenderer.setXAxisMax(x);

    // set the left side to one minute earlier 60000 miliseconds
    mRenderer.setXAxisMin(x - 60000);

    mRenderer.setYAxisMin(MIN_HEART_RATE);
    mRenderer.setYAxisMax(MAX_HEART_RATE);

    mRenderer.setLabelsTextSize(LABELTEXTSIZE);
    renderer.setFillPoints(true);
    renderer.setLineWidth(2);

    renderer.setPointStyle(style);
    mRenderer.setShowLegend(false);
    mRenderer.setChartTitle(title);
    mRenderer.setShowGrid(true);
    mRenderer.setGridColor(gridcolor);
    mRenderer.setXLabels(11);
    mRenderer.setYLabels(5);

    mRenderer.setAxisTitleTextSize(25);
    mRenderer.setChartTitleTextSize(30);
    mRenderer.setLabelsTextSize(20);
    mRenderer.setLegendTextSize(15);
    mRenderer.setPointSize(2f);
    mRenderer.setMargins(new int[] {20, 30, 15, 0});

    mRenderer.setYLabelsAlign(Align.RIGHT);
    mDataset.removeSeries(0);

    mDataset.addSeries(series);

    renderer.setColor(linecolor);
    context = getApplicationContext();
    mRenderer.setApplyBackgroundColor(true);
    mRenderer.setBackgroundColor(bgcolor);
    mRenderer.addSeriesRenderer(renderer);

    chartview = ChartFactory.getTimeChartView(context, mDataset, mRenderer, null);
    chartview.invalidate();
    ((TextView) findViewById(R.id.heartratelabel)).setText("HR:" + pulserate);

    chartview.repaint();

    FrameLayout chartlayout = (FrameLayout) findViewById(R.id.chartlayout);
    chartlayout.removeAllViewsInLayout();

    chartlayout.addView(
        chartview,
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT));

    status
        .checkForClear(); // this needs to be done time to time regularly so statuses are not stuck
                          // on.
  }
  private void OpenChart() {
    int x[] = {10, 18, 32, 21, 48, 60, 53, 80};
    XYSeries xySeries = new XYSeries("X Series");
    for (int i = 0; i < 8; i++) {
      xySeries.add(i, x[i]);
    }
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    dataset.addSeries(xySeries);

    XYSeriesRenderer renderer = new XYSeriesRenderer();
    renderer.setColor(Color.GREEN);
    renderer.setPointStyle(PointStyle.DIAMOND);
    renderer.setDisplayChartValues(true);
    renderer.setLineWidth(2);
    renderer.setFillPoints(true);

    XYMultipleSeriesRenderer multipleSeriesRenderer = new XYMultipleSeriesRenderer();
    multipleSeriesRenderer.setChartTitle("X-Y Chart");
    multipleSeriesRenderer.setXTitle("X Values");
    multipleSeriesRenderer.setYTitle("Y values");
    multipleSeriesRenderer.setZoomButtonsVisible(true);
    multipleSeriesRenderer.setXLabels(0);
    multipleSeriesRenderer.setPanEnabled(false);
    multipleSeriesRenderer.setShowGrid(true);
    multipleSeriesRenderer.setClickEnabled(true);

    for (int i = 0; i < 8; i++) {
      multipleSeriesRenderer.addXTextLabel(i, mMonth[i]);
    }

    multipleSeriesRenderer.addSeriesRenderer(renderer);

    LinearLayout chart_container = (LinearLayout) findViewById(R.id.chart_layout);

    mChart =
        (GraphicalView)
            ChartFactory.getLineChartView(getBaseContext(), dataset, multipleSeriesRenderer);

    mChart.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            SeriesSelection series_selection = mChart.getCurrentSeriesAndPoint();

            if (series_selection != null) {
              int series_index = series_selection.getSeriesIndex();
              String select_seriese = "X Series";
              if (series_index == 0) {
                select_seriese = "X Series";
              } else {
                select_seriese = "Y Series";
              }
              String month = mMonth[(int) series_selection.getXValue()];
              int amount = (int) series_selection.getValue();
              Toast.makeText(
                      getBaseContext(),
                      select_seriese + "in" + month + ":" + amount,
                      Toast.LENGTH_LONG)
                  .show();
            }
          }
        });
    chart_container.addView(mChart);
  }