Пример #1
0
  /**
   * There is one chart for each signal type. Returns the chart component of a specific signal type.
   *
   * @return
   */
  public LineChart getChart(String signalTypeId) {
    if (!charts.containsKey(signalTypeId)) {
      // Create a chart component
      // chart = (LineChart) findViewById(R.id.chart);
      final LineChart chart = new LineChart(this);
      // chart.setUnit("Db");
      chart.setUnit("");
      // chart.setDrawUnitsInChart(true);
      chart.setDrawYValues(false);
      chart.setDrawBorder(false);
      chart.setTouchEnabled(true);
      chart.setDragEnabled(true);
      chart.setNoDataTextDescription("No data gathered.");
      chart.setDescription("Samples");
      chart.setPinchZoom(true); // if disabled, scaling can be done on x- and y-axis separately
      // set an alternative background color
      // mChart.setBackgroundColor(Color.GRAY)

      // Creates a chart tab.
      // http://www.java2s.com/Code/Android/UI/DynamicTabDemo.htm
      // http://www.java2s.com/Code/Android/UI/UsingatabcontentfactoryforthecontentviaTabHostTabSpecsetContentandroidwidgetTabHostTabContentFactory.htm
      TabHost.TabSpec spec = tabHost.newTabSpec(signalTypeId);
      spec.setIndicator(signalTypeId);
      spec.setContent(
          new TabHost.TabContentFactory() {
            public View createTabContent(String tag) {
              return chart;
            }
          });
      tabHost.addTab(spec);
      // addContentToTab(tabHost.getChildCount(), chart);

      charts.put(signalTypeId, chart);
      tabHost.invalidate();
    }

    return charts.get(signalTypeId);
  }
Пример #2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    rootView = inflater.inflate(R.layout.kommfort, container, false);
    RelativeLayout relativ = (RelativeLayout) rootView.findViewById(R.id.bak);

    mLineChart = (LineChart) relativ.findViewById(R.id.linechartkommfort);
    mLineChart.setOnChartValueSelectedListener(this);

    // no description text
    mLineChart.setDescription("Beschleunigungskraefte");
    mLineChart.setNoDataTextDescription("You need to provide data for the chart.");

    // enable highlighting
    mLineChart.setHighlightEnabled(true);

    // enable touch gestures
    mLineChart.setTouchEnabled(true);

    // enable scaling and dragging
    mLineChart.setDragEnabled(true);
    mLineChart.setScaleEnabled(true);
    mLineChart.setDrawGridBackground(false);

    // if disabled, scaling can be done on x- and y-axis separately
    mLineChart.setPinchZoom(true);

    // set an alternative background color
    mLineChart.setBackgroundColor(Color.WHITE);

    LineData data = new LineData();
    data.setValueTextColor(Color.BLACK);

    // add empty data
    mLineChart.setData(data);

    // get the legend (only possible after setting data)
    Legend l = mLineChart.getLegend();

    // modify the legend ...
    // l.setPosition(LegendPosition.LEFT_OF_CHART);
    l.setForm(Legend.LegendForm.LINE);

    l.setTextColor(Color.BLACK);

    XAxis xl = mLineChart.getXAxis();

    xl.setTextColor(Color.BLACK);
    xl.setDrawGridLines(false);
    xl.setAvoidFirstLastClipping(true);

    YAxis leftAxis = mLineChart.getAxisLeft();

    leftAxis.setTextColor(Color.BLACK);
    leftAxis.setAxisMaxValue(2f);
    leftAxis.setAxisMinValue(-2f);
    leftAxis.setStartAtZero(false);
    leftAxis.setDrawGridLines(true);

    YAxis rightAxis = mLineChart.getAxisRight();
    rightAxis.setEnabled(false);

    Button zukamm = (Button) rootView.findViewById(R.id.butonzumkreis);
    // TextView zubesh=(TextView) rootView.findViewById(R.id.zubeschleunigungskraefte);

    // Layout button=(Layout) rootView.findViewById(R.id.);

    zukamm.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getActivity(), KammsherKreis.class);
            Kommfort.this.startActivity(intent);
          }
        });

    /**
     * zubesh.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {
     * Intent myIntent = new Intent(getActivity(), Beschleunigungskraefte.class);
     * getActivity().startActivityForResult(myIntent,100); } });
     */
    return rootView;
  }
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LineView = inflater.inflate(R.layout.analysis_bar, container, false);
    initView();

    // no description text
    mChart.setDescription("");

    // enable value highlighting
    mChart.setHighlightEnabled(true);

    // enable touch gestures
    mChart.setTouchEnabled(true);

    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);

    // if disabled, scaling can be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    mChart.setDrawGridBackground(true);

    //  tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

    XAxis x = mChart.getXAxis();
    //  x.setTypeface(tf);
    x.setEnabled(true);

    YAxis y = mChart.getAxisLeft();
    //  y.setTypeface(tf);
    y.setLabelCount(5);
    y.setEnabled(true);

    mChart.getAxisRight().setEnabled(true);

    // add data
    catchData();

    Date dt = new Date();
    SimpleDateFormat matter1 = new SimpleDateFormat("dd");
    int days = Integer.parseInt(matter1.format(dt));
    log.e("days = " + days);
    setData(days - 9, 10, 100);

    mChart.getLegend().setEnabled(true);

    mChart.animateXY(2000, 2000);

    // dont forget to refresh the drawing
    /*ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData()
            .getDataSets();

    for (LineDataSet set : sets) {
        if (set.isDrawCubicEnabled())
            set.setDrawCubic(false);
        else
            set.setDrawCubic(true);
    }*/
    mChart.invalidate();

    return LineView;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    final View view = inflater.inflate(R.layout.fragment_chart_tab, container, false);

    btnPrevious = (ImageButton) view.findViewById(R.id.btnPrevious);
    btnPrevious.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            convertExecutor.execute(
                new Runnable() {
                  @Override
                  public void run() {
                    if (currentGraph <= 1) {
                      return;
                    }

                    currentGraph--;
                    ChartCollection collection =
                        fromDevice ? fileManager.getCollection() : fileManager.getPcaCollection();
                    final Map<Double, Double> mapData =
                        collection.getCharData(currentGraph - 1).getData();
                    //                        final double[] data = new
                    // double[mapData.values().size()];
                    //
                    //                        for (int i = 0; i < mapData.values().size(); i++) {
                    //                            data[i] = mapData.get(i);
                    //                        }

                    mainHandler.post(
                        new Runnable() {
                          @Override
                          public void run() {
                            drawGraph(mapData);
                            txtCurrent.setText(String.valueOf(currentGraph));
                          }
                        });
                  }
                });
          }
        });

    btnNext = (ImageButton) view.findViewById(R.id.btnNext);
    btnNext.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            convertExecutor.execute(
                new Runnable() {
                  @Override
                  public void run() {
                    if (currentGraph >= totalGraphs) {
                      return;
                    }

                    currentGraph++;
                    ChartCollection collection =
                        fromDevice ? fileManager.getCollection() : fileManager.getPcaCollection();
                    final Map<Double, Double> mapData =
                        collection.getCharData(currentGraph - 1).getData();
                    //                        final double[] data = new
                    // double[mapData.values().size()];
                    //
                    //                        for (int i = 0; i < mapData.values().size(); i++) {
                    //                            data[i] = mapData.get(i);
                    //                        }

                    mainHandler.post(
                        new Runnable() {
                          @Override
                          public void run() {
                            drawGraph(mapData);

                            txtCurrent.setText(String.valueOf(currentGraph));
                          }
                        });
                  }
                });
          }
        });
    txtCurrent = (TextView) view.findViewById(R.id.txtCurrentGraph);
    txtTotal = (TextView) view.findViewById(R.id.txtTotalGraph);

    chart = (LineChart) view.findViewById(R.id.chart);
    chart.setNoDataText("Aguardando dados...");
    chart.setScaleYEnabled(false);
    chart.setPinchZoom(true);

    if (fromDevice) {
      YAxis leftAxis = chart.getAxisLeft();
      leftAxis.setAxisMinValue(0);
      leftAxis.setAxisMaxValue(100);
    }
    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setEnabled(false);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

    loadData(true);

    return view;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_linechart);

    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);

    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);

    mSeekBarX.setProgress(45);
    mSeekBarY.setProgress(100);

    mSeekBarY.setOnSeekBarChangeListener(this);
    mSeekBarX.setOnSeekBarChangeListener(this);

    mChartView = (ChartView) findViewById(R.id.chart1);
    mChart = (LineChart) mChartView.getChart();
    mChart.setOnChartValueSelectedListener(this);

    // if enabled, the chart will always start at zero on the y-axis
    mChart.setStartAtZero(true);

    // enable the drawing of values into the chart
    mChart.setDrawYValues(true);

    mChart.setDrawBorder(true);
    mChart.setBorderPositions(new BorderPosition[] {BorderPosition.BOTTOM});

    // no description text
    mChart.setDescription("");

    // invert the y-axis
    mChart.setInvertYAxisEnabled(true);

    // enable value highlighting
    mChart.setHighlightEnabled(true);

    // enable touch gestures
    mChart.setTouchEnabled(true);

    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);

    // if disabled, scaling can be done on x- and y-axis separately
    mChart.setPinchZoom(true);

    // set an alternative background color
    // mChart.setBackgroundColor(Color.GRAY);

    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);

    // define an offset to change the original position of the marker
    // (optional)
    mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());

    // set the marker to the chart
    mChart.setMarkerView(mv);

    // enable/disable highlight indicators (the lines that indicate the
    // highlighted Entry)
    mChart.setHighlightIndicatorEnabled(false);

    XLabels xl = mChart.getXLabels();
    xl.setAvoidFirstLastClipping(true);

    // add data
    setData(25, 50);

    // // restrain the maximum scale-out factor
    // mChart.setScaleMinima(3f, 3f);
    //
    // // center the view to a specific position inside the chart
    // mChart.centerViewPort(10, 50);

    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();

    // modify the legend ...
    // l.setPosition(LegendPosition.LEFT_OF_CHART);
    l.setForm(LegendForm.LINE);

    // dont forget to refresh the drawing
    mChartView.invalidate();
  }
Пример #6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //        setContentView(R.layout.activity_realtime_chart);
    //        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //        setSupportActionBar(toolbar);

    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_realtime_chart);

    //        mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);

    mChart.setDescription("Sleep Cycle live chart");
    mChart.setNoDataTextDescription("No sleep data available.");

    mChart.setTouchEnabled(true);

    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);

    mChart.setPinchZoom(true);

    LineData data = new LineData();

    mChart.setData(data);

    Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

    Legend l = mChart.getLegend();
    l.setForm(Legend.LegendForm.LINE);
    l.setTypeface(tf);
    l.setTextColor(Color.WHITE);

    XAxis xl = mChart.getXAxis();
    xl.setTypeface(tf);
    xl.setTextColor(Color.WHITE);
    xl.setDrawGridLines(false);
    xl.setAvoidFirstLastClipping(true);
    xl.setSpaceBetweenLabels(5);
    xl.setEnabled(true);

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(tf);
    leftAxis.setTextColor(Color.WHITE);
    leftAxis.setAxisMaxValue(100f);
    leftAxis.setAxisMinValue(0f);
    leftAxis.setStartAtZero(false);
    leftAxis.setDrawGridLines(true);

    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setEnabled(false);

    //        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    //        fab.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View view) {
    //                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
    //                        .setAction("Action", null).show();
    //            }
    //        });
  }