Пример #1
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);
  }
 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);
 }
Пример #3
0
 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);
 }
  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
  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);
  }
  @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));
  }
  private void setupTopChart() {

    // Creating an  XYSeries for Sound
    visitsSeries = new XYSeries("");
    secondSeries = new XYSeries("");

    // Creating a dataset to hold each series
    dataset = new XYMultipleSeriesDataset();
    Sdataset = new XYMultipleSeriesDataset();

    // Adding Visits Series to the dataset
    dataset.addSeries(visitsSeries);
    Sdataset.addSeries(secondSeries);

    // Adding datasets together
    multiDateSet = new XYMultipleSeriesDataset();
    multiDateSet.addSeries(visitsSeries);
    multiDateSet.addSeries(secondSeries);

    // Creating XYSeriesRenderer to customize visitsSeries
    visitsRenderer = new XYSeriesRenderer();
    visitsRenderer.setColor(getResources().getColor(R.color.colorAccent));
    visitsRenderer.setPointStyle(PointStyle.CIRCLE);
    visitsRenderer.setFillPoints(true);
    visitsRenderer.setDisplayChartValues(false);
    visitsRenderer.setLineWidth(10);

    // Creating a XYMultipleSeriesRenderer to customize the whole chart
    multiRenderer = new XYMultipleSeriesRenderer();

    multiRenderer.setMargins(new int[] {0, 0, 0, 0});
    multiRenderer.setPanEnabled(false);
    multiRenderer.setShowLegend(false);
    multiRenderer.setChartTitle("");
    // multiRenderer.setFitLegend(true);

    // Eliminate the S***e
    multiRenderer.setApplyBackgroundColor(true);
    multiRenderer.setXTitle("");
    multiRenderer.setShowLabels(false);
    multiRenderer.setShowAxes(false);

    multiRenderer.setMarginsColor(Color.TRANSPARENT);
    multiRenderer.setBackgroundColor(Color.TRANSPARENT);
    multiRenderer.setXLabelsColor(Color.TRANSPARENT);
    multiRenderer.setYLabelsColor(0, Color.TRANSPARENT);
    multiRenderer.setGridColor(Color.TRANSPARENT);
    multiRenderer.setXLabelsPadding(0);
    multiRenderer.setYLabelsPadding(0);
    multiRenderer.setBarWidth(100);

    // Establish Beginning Dimensions
    multiRenderer.setXAxisMin(0);
    multiRenderer.setXAxisMax(10);
    multiRenderer.setYAxisMin(0);
    multiRenderer.setYAxisMax(0);

    // Make the bar graphs touching
    multiRenderer.setBarSpacing(0);

    // Adding visitsRenderer to multipleRenderer
    // Note: The order of adding dataseries to dataset and renderers to multipleRenderer
    // should be same
    multiRenderer.addSeriesRenderer(visitsRenderer);
    multiRenderer.addSeriesRenderer(visitsRenderer);

    // Getting a reference to LinearLayout of the RecordActivity Layout
    LinearLayout chartContainer = (LinearLayout) findViewById(R.id.chartTop);

    mChart =
        (GraphicalView)
            ChartFactory.getBarChartView(
                getBaseContext(),
                multiDateSet,
                multiRenderer,
                org.achartengine.chart.BarChart.Type.DEFAULT);

    // Adding the Line Chart to the LinearLayout
    chartContainer.addView(mChart);
  }
Пример #8
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;
  }
  // 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.
  }