Exemplo n.º 1
0
  private static XYMultipleSeriesRenderer getDemoRenderer() {

    XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
    renderer.setAxisTitleTextSize(16);
    renderer.setChartTitleTextSize(20);
    renderer.setLabelsTextSize(15);
    renderer.setLegendTextSize(15);
    renderer.setPointSize(5f);
    renderer.setMargins(new int[] {20, 30, 15, 0});

    XYSeriesRenderer r = new XYSeriesRenderer();
    r.setColor(Color.DKGRAY);
    r.setFillPoints(false);
    renderer.addSeriesRenderer(r);

    int count = 0;
    while (count < 20) {
      if (Compte_Present[count] != null) {
        r = new XYSeriesRenderer();
        //		    r.setPointStyle(PointStyle.CIRCLE);
        r.setColor(_DataPool.BudgetColor(Compte_Present[count]));
        r.setFillPoints(false);
        renderer.addSeriesRenderer(r);
      }
      count++;
    }

    renderer.setAxesColor(Color.DKGRAY);
    renderer.setLabelsColor(Color.LTGRAY);
    return renderer;
  }
Exemplo n.º 2
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);
   }
 }
 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;
 }
Exemplo n.º 4
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);
  }
  @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);
  }
 private XYMultipleSeriesRenderer getDemoRenderer() {
   XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
   renderer.setAxisTitleTextSize(16);
   renderer.setChartTitleTextSize(20);
   renderer.setLabelsTextSize(15);
   renderer.setLegendTextSize(15);
   renderer.setPointSize(5f);
   renderer.setMargins(new int[] {20, 30, 15, 0});
   XYSeriesRenderer r = new XYSeriesRenderer();
   r.setColor(Color.BLUE);
   r.setPointStyle(PointStyle.SQUARE);
   r.setFillBelowLine(true);
   r.setFillBelowLineColor(Color.WHITE);
   r.setFillPoints(true);
   renderer.addSeriesRenderer(r);
   r = new XYSeriesRenderer();
   r.setPointStyle(PointStyle.CIRCLE);
   r.setColor(Color.GREEN);
   r.setFillPoints(true);
   renderer.addSeriesRenderer(r);
   renderer.setAxesColor(Color.DKGRAY);
   renderer.setLabelsColor(Color.LTGRAY);
   return renderer;
 }
  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);
  }
Exemplo n.º 8
0
  private void openChart() {

    String[] chartTitles;
    chartTitles = new String[] {"Total"};
    List<double[]> values = new ArrayList<double[]>();
    values.add(mStatsDataDaysList.getDataDoubleArray());
    int totalXlength = 0;

    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

    List<double[]> xAxisValues = new ArrayList<double[]>();
    xAxisValues.add(mStatsDataDaysList.getXDoubleArray());

    for (int i = 0; i < chartTitles.length; i++) {
      XYSeries series = new XYSeries(chartTitles[i]);
      double[] xV = xAxisValues.get(i);
      double[] yV = values.get(i);
      int seriesLength = xV.length;
      for (int k = 0; k < seriesLength; k++) {
        System.out.println("LOG X is " + xV[k] + " y is " + yV[k]);
        series.add(xV[k] - 1, yV[k]);
      }
      dataset.addSeries(series);
    }

    XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();
    incomeRenderer.setColor(Color.WHITE);
    incomeRenderer.setPointStyle(PointStyle.CIRCLE);
    incomeRenderer.setFillPoints(true);
    incomeRenderer.setDisplayChartValues(true);
    incomeRenderer.setDisplayChartValuesDistance(15);
    incomeRenderer.setDisplayBoundingPoints(false); // for hiding the series when we scroll

    // Creating a XYMultipleSeriesRenderer to customize the whole chart
    XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
    multiRenderer.setChartTitle(getString(R.string.my_mined_km_history));
    multiRenderer.setXTitle(getString(R.string.days));
    multiRenderer.setYTitle(getString(R.string.km));
    multiRenderer.setZoomButtonsVisible(true);
    multiRenderer.setBackgroundColor(0xf7f7f7);
    multiRenderer.setMarginsColor(0xf7f7f7);
    multiRenderer.setMargins(new int[] {50, 60, 60, 30});

    multiRenderer.setXLabelsAlign(Align.CENTER);
    multiRenderer.setYLabelsAlign(Align.RIGHT);
    multiRenderer.setPanEnabled(true, false); // scroll only x axis so true
    multiRenderer.setZoomEnabled(ZOOM_X, false);

    multiRenderer.setPointSize(8); // increase the width of point size
    multiRenderer.setXLabelsPadding(10);

    if (Utils.getScreenDendity(this) > DisplayMetrics.DENSITY_HIGH) {
      multiRenderer.setAxisTitleTextSize(20);
      multiRenderer.setChartTitleTextSize(25);
      multiRenderer.setLabelsTextSize(20);
      multiRenderer.setPointSize(8);
      incomeRenderer.setLineWidth(4);
      incomeRenderer.setChartValuesTextSize(20);
    } else {
      multiRenderer.setAxisTitleTextSize(12);
      multiRenderer.setChartTitleTextSize(18);
      multiRenderer.setLabelsTextSize(12);
      multiRenderer.setPointSize(5);
      incomeRenderer.setLineWidth(2);
      incomeRenderer.setChartValuesTextSize(15);
    }

    xyValues = new LinkedHashMap<Integer, String>();

    for (int i = 0; i < chartTitles.length; i++) {
      double[] xV = xAxisValues.get(i);
      totalXlength = xV.length;
      System.out.println("LOG len is " + totalXlength);
      for (int j = 0; j < totalXlength; j++) {
        multiRenderer.addXTextLabel(j + 1, Utils.addDays(xV[j], mInitialDateUser));
        xyValues.put(j + 1, Utils.addDays(xV[j], mInitialDateUser));
      }
    }

    multiRenderer.setXLabels(0);
    multiRenderer.setShowAxes(false);

    multiRenderer.setXAxisMin(totalXlength - 5);
    multiRenderer.setXAxisMax(totalXlength + 1);

    if (totalXlength <= X_AXIS_MAX) {
      multiRenderer.setXAxisMin(0);
      multiRenderer.setXAxisMax(totalXlength);
    }

    multiRenderer.setPanEnabled(true);
    multiRenderer.setPanLimits(new double[] {0, totalXlength + 1, 0, 0});

    multiRenderer.setYAxisMin(Utils.getMinValueFromList(values));
    multiRenderer.setYAxisMax(Utils.getMaxValueFromList(values));
    multiRenderer.setAxesColor(Color.GRAY);
    multiRenderer.setLabelsColor(Color.WHITE);
    multiRenderer.addSeriesRenderer(incomeRenderer);

    // Creating a Time Chart
    mChartView2 =
        (GraphicalView)
            ChartFactory.getTimeChartView(getBaseContext(), dataset, multiRenderer, "dd-MMM-yyyy");

    multiRenderer.setClickEnabled(true);
    multiRenderer.setSelectableBuffer(10);

    // Setting a click event listener for the graph
    mChartView2.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            SeriesSelection seriesSelection = mChartView2.getCurrentSeriesAndPoint();
            double[] xy = mChartView2.toRealPoint(0);

            if (seriesSelection != null) {

              //                  debug
              Log.d("Punto", seriesSelection.getXValue() + ", " + seriesSelection.getValue());
              //                  debug
              Log.d(
                  "Chart point",
                  "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.makeText(
                      getBaseContext(),
                      ""
                          + xyValues.get((int) seriesSelection.getXValue())
                          + " , "
                          + seriesSelection.getValue()
                          + " "
                          + getString(R.string.km),
                      Toast.LENGTH_SHORT)
                  .show();
            }
          }
        });

    // Adding the Line Chart to the LinearLayout
    mLayoutChart2.addView(mChartView2);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
      Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
      finish();
      return;
    }

    dispRunTime = (TextView) findViewById(R.id.dispRunTime);
    dispTemp = (TextView) findViewById(R.id.dispTemp);
    dispRoc = (TextView) findViewById(R.id.dispRoc);
    dispWRoC = (TextView) findViewById(R.id.dispTargRoc);
    dispMaxT = (TextView) findViewById(R.id.dispMaxTemp);
    alarmSet = (ZoomControls) findViewById(R.id.alarmSet);
    dispAlarmTemp = (TextView) findViewById(R.id.AlarmTemp);

    //		dispLogData = (ListView) findViewById(R.id.listLogData);
    //		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    //				android.R.layout.simple_list_item_1, logValues);
    //		setListAdapter(adapter);

    tempBar = (SeekBar) findViewById(R.id.tempBar);
    tempBar.setOnSeekBarChangeListener(this);
    tempBar.setMax(100);
    tempBar.setProgress(50);

    Log.v(TAG, "onCreate - add data");

    mDataset.addSeries(liveGraphXYSeries);
    Log.v(TAG, "onCreate - set render");

    mRenderer.setAxisTitleTextSize(14);
    mRenderer.setChartTitleTextSize(16);
    mRenderer.setLabelsTextSize(13);
    mRenderer.setLegendTextSize(13);
    mRenderer.setPointSize(5f);
    mRenderer.setMargins(new int[] {10, 20, 8, 10});
    // mRenderer.setXAxisMax(600);
    mRenderer.setYAxisMax(240);

    int[] colors = new int[] {Color.GREEN};
    PointStyle[] styles = new PointStyle[] {PointStyle.POINT};
    int length = colors.length;
    for (int i = 0; i < length; i++) {
      Log.v(TAG, "onCreate - add renderes");

      XYSeriesRenderer r = new XYSeriesRenderer();
      r.setColor(colors[i]);
      r.setPointStyle(styles[i]);
      mRenderer.addSeriesRenderer(r);
    }

    Button start = (Button) findViewById(R.id.ButtonStart);
    Button stop = (Button) findViewById(R.id.ButtonStop);
    Button reset = (Button) findViewById(R.id.buttonReset);
    Button acceptTemps = (Button) findViewById(R.id.buttonAcceptVariance);

    start.setOnClickListener(startClickHandler);
    stop.setOnClickListener(stopClickHandler);
    reset.setOnClickListener(resetClickHandler);
    acceptTemps.setOnClickListener(acceptTempsClickHandler);
    alarmSet.setOnZoomInClickListener(tempUpClickHandler);
    alarmSet.setOnZoomOutClickListener(tempDownClickHandler);

    Intent a = new Intent(this, TempService.class);
    startService(a);
    // Binding ..this block can also start service if not started already
    Intent bindIntent = new Intent(this, TempService.class);
    bindService(bindIntent, serviceConncetion, Context.BIND_AUTO_CREATE);
    // Register Broadcast Receiver
    IntentFilter filter = new IntentFilter(TempService.MYOWNACTIONFILTER);
    registerReceiver(myReceiver, filter);

    // Set our 'default' temp  - entire array is set so the average is what we expect.
    for (int i = 0; i < 5; i++) tempValues[i] = runTemp;

    // dispTemp.setText("Temp: " + String.valueOf(tempValues[0]));

    Log.v(TAG, "onCreate - main");

    if (mChartView == null) {
      Log.v(TAG, "onCreate - before chart layout");
      LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
      Log.v(TAG, "onCreate - before chart Factory");

      mChartView = ChartFactory.getLineChartView(this, mDataset, mRenderer);
      Log.v(TAG, "onCreate - before chart addview");
      layout.addView(
          mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    } else {
      mChartView.repaint();
    }

    final EditText edittext = (EditText) findViewById(R.id.simulateSpeed);
    edittext.setOnKeyListener(
        new OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
              // Perform action on key press
              currentSimulateSpeed = Integer.parseInt(edittext.getText().toString());
              tempUpdService.simluateMode(currentSimulateMode, currentSimulateSpeed);
              return true;
            }
            return false;
          }
        });
    final CheckBox checkbox = (CheckBox) findViewById(R.id.cSimulate);
    if (checkbox != null) {
      checkbox.setOnClickListener(
          new OnClickListener() {
            public void onClick(View v) {
              // Perform action on clicks, depending on whether it's now checked
              if (((CheckBox) v).isChecked()) {
                currentSimulateMode = true;
              } else {
                currentSimulateMode = false;
              }

              tempUpdService.simluateMode(currentSimulateMode, currentSimulateSpeed);
            }
          });
    }

    OnClickListener radio_listener =
        new OnClickListener() {
          public void onClick(View v) {
            // Perform action on clicks
            RadioButton rb = (RadioButton) v;
            Toast.makeText(Coffee2ohActivity.this, rb.getText(), Toast.LENGTH_SHORT).show();
            switch (v.getId()) {
              case R.id.runAuto:
                tempUpdService.setRunMode(TempService.RunModeAuto);
                break;
              case R.id.runOff:
                tempUpdService.setRunMode(TempService.RunModeStop);
                break;
              case R.id.runHold:
                tempUpdService.setRunMode(TempService.RunModeHold);
                break;
              case R.id.runManual:
                tempUpdService.setRunMode(TempService.RunModeManual);
                break;
            }
          }
        };

    final RadioButton rbAuto = (RadioButton) findViewById(R.id.runAuto);
    final RadioButton rbStop = (RadioButton) findViewById(R.id.runOff);
    final RadioButton rbHold = (RadioButton) findViewById(R.id.runHold);
    final RadioButton rbManual = (RadioButton) findViewById(R.id.runManual);
    rbAuto.setOnClickListener(radio_listener);
    rbManual.setOnClickListener(radio_listener);
    rbStop.setOnClickListener(radio_listener);
    if (rbHold != null) {
      rbHold.setOnClickListener(radio_listener);
    }
  } // End OnCreate
Exemplo n.º 10
0
  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();
    //	      }
  }
Exemplo n.º 11
0
  // 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.
  }