예제 #1
0
  public void formatChartDataNoThread(
      final List<BankModel> posts, final LineChart chart, final Context context) {
    final ArrayList<String> cashXVals = new ArrayList<String>();
    final ArrayList<Entry> cashYVals1 = new ArrayList<Entry>();
    final ArrayList<Entry> credYVals1 = new ArrayList<Entry>();
    addXandYCoords(posts, cashXVals, cashYVals1, credYVals1);
    LineDataSet set = new LineDataSet(cashYVals1, "DataSet 1");
    LineDataSet set2 = new LineDataSet(credYVals1, "DataSet 2");
    formatDataSet(set, Color.parseColor("#4CAF50"));
    formatDataSet(set2, Color.parseColor("#F44336"));

    ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
    dataSets.add(set);
    dataSets.add(set2);
    LineData data = new LineData(cashXVals, dataSets);
    CustomMarkerView mv = new CustomMarkerView(context, R.layout.marker_view);
    chart.setTouchEnabled(true);
    chart.setMarkerView(mv);
    chart.setData(data);
    chart.setDescription("");
    chart.invalidate();
  }
예제 #2
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);
  }
예제 #3
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;
  }
예제 #4
0
  public void drawLineChart(
      View v,
      int averageCrowdValue,
      List<Integer> todaysCrowdValues,
      List<Integer> rodCrowdValues) {

    /* Create data entries1 and labels for todaysCrowd Values*/
    ArrayList<Entry> entries1 = new ArrayList<>();
    ArrayList<String> labels = new ArrayList<>();
    for (int hour = 0; hour < todaysCrowdValues.size(); hour++) {
      entries1.add(new Entry(todaysCrowdValues.get(hour), hour));
      labels.add("" + hour);
    }

    /* Create data entries2 and labels for rodCrowdValues Values*/
    ArrayList<Entry> entries2 = new ArrayList<>();
    for (int hour = 0; hour < rodCrowdValues.size(); hour++) {
      entries2.add(new Entry(rodCrowdValues.get(hour), hour + todaysCrowdValues.size()));
      labels.add("" + (hour + todaysCrowdValues.size()));
    }

    /* Create dataentires for averageCrowdValue */
    ArrayList<Entry> entries3 = new ArrayList<>();
    entries3.add(new Entry(averageCrowdValue, 0));
    entries3.add(new Entry(averageCrowdValue, 23));

    // Create dataset from data entries1
    LineDataSet dataset1 = new LineDataSet(entries1, "Today's Crowd");
    LineDataSet dataset2 = new LineDataSet(entries2, "Predicted Crowd");
    LineDataSet dataset3 = new LineDataSet(entries3, "Average Crowd");

    // Set the color for this dataset
    dataset1.setColor(Color.rgb(0, 37, 76)); // GT Navy
    dataset2.setColor(Color.rgb(238, 178, 17)); // Buzz Gold
    dataset3.setColor(Color.rgb(197, 147, 83)); // GT Gold

    // Aggregate all data sets
    ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
    dataSets.add(dataset1);
    dataSets.add(dataset2);
    dataSets.add(dataset3);

    /* Create the chart */
    LineChart chart = (LineChart) v.findViewById(R.id.chart);

    // Hide Labels and grid lines from x axis
    chart.getXAxis().setDrawGridLines(false);
    chart.getXAxis().setDrawLabels(false);

    // Hide labels and grid lines from y axis
    chart.getAxisLeft().setDrawGridLines(false);
    chart.getAxisLeft().setDrawLabels(false);
    chart.getAxisRight().setDrawGridLines(false);
    chart.getAxisRight().setDrawLabels(false);

    // Dont label each node on graph
    chart.setDrawMarkerViews(false);
    LineData data = new LineData(labels, dataSets);
    chart.setData(data);

    chart.setDescription("Today's Crowd");

    // animations
    chart.animateY(1000);
  }
  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
  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();
  }
예제 #7
0
  private void drawChart() {
    BPRecord[] recs = mRecords;
    LineChart chart = (LineChart) findViewById(R.id.chart);
    ArrayList<Entry> valsHigh = new ArrayList<Entry>();
    ArrayList<Entry> valsLow = new ArrayList<Entry>();
    // ArrayList<Entry> heartRate = new ArrayList<Entry>();
    // ArrayList<Entry> o2Index = new ArrayList<Entry>();
    // ArrayList<Entry> avgArtP = new ArrayList<Entry>();
    ArrayList<String> xVals = new ArrayList<String>();
    Date firstTime = null;
    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    SimpleDateFormat f2 = new SimpleDateFormat("MM/dd HH:mm");
    for (int i = 0; i < recs.length; ++i) {
      BPRecord rec = recs[i];
      int x = 0; // minutes from first data
      Date time = new Date();
      try {
        time = f.parse(rec.dateTime);
      } catch (ParseException ex) {
        Log.d("GetBPDate", "Exception:" + ex.toString());
        continue;
      }
      if (firstTime == null) {
        firstTime = time;
      } else {
        x = (int) ((time.getTime() - firstTime.getTime()) / 60000);
      }
      x = i;
      xVals.add(f2.format(time));
      valsHigh.add(new Entry(rec.systolic, x));
      valsLow.add(new Entry(rec.diastolic, x));
      // heartRate.add(new Entry(rec.heartRate,x));
      // avgArtP.add(new Entry(rec.avg_art_pressure,x));
      // o2Index.add(new Entry(rec.o2Index/100,x));
    }
    String hp = getResources().getString(R.string.hightPressure);
    String lp = getResources().getString(R.string.lowPressure);
    /*
    String hr = getResources().getString(R.string.heartBeatLabel);
    String avgAP = getResources().getString(R.string.average_artery_pressure);
    String o2 = getResources().getString(R.string.O2Index);
    */
    LineDataSet setHigh = new LineDataSet(valsHigh, hp);
    setHigh.setAxisDependency(YAxis.AxisDependency.LEFT);
    setHigh.setDrawCircles(false);
    setHigh.setColor(Color.RED);
    setHigh.setValueFormatter(new IntFormatter());
    setHigh.setValueTextSize(10);
    LineDataSet setLow = new LineDataSet(valsLow, lp);
    setLow.setAxisDependency(YAxis.AxisDependency.LEFT);
    setLow.setColor(Color.BLUE);
    setLow.setDrawCircles(false);
    setLow.setValueFormatter(new IntFormatter());
    setLow.setValueTextSize(10);
    /*
    LineDataSet setHr = new LineDataSet(heartRate, hr);
    setHr.setAxisDependency(YAxis.AxisDependency.LEFT);
    setHr.setColor(Color.GREEN);
    setHr.setDrawCircles(false);
    setHr.setValueFormatter(new IntFormatter());
    setHr.setValueTextSize(10);
    LineDataSet setAAP = new LineDataSet(avgArtP, avgAP);
    setAAP.setAxisDependency(YAxis.AxisDependency.LEFT);
    setAAP.setColor(Color.DKGRAY);
    setAAP.setDrawCircles(false);
    setAAP.setValueFormatter(new IntFormatter());
    setAAP.setValueTextSize(10);
    LineDataSet setO2 = new LineDataSet(o2Index, o2);
    setO2.setAxisDependency(YAxis.AxisDependency.LEFT);
    setO2.setColor(Color.CYAN);
    setO2.setDrawCircles(false);
    setO2.setValueFormatter(new IntFormatter());
    setO2.setValueTextSize(10);
    */
    ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
    dataSets.add(setHigh);
    dataSets.add(setLow);
    /*
    dataSets.add(setHr);
    dataSets.add(setAAP);
    dataSets.add(setO2);
    */

    /*
    xVals.add("12-15"); xVals.add("12-17"); xVals.add("12-18"); xVals.add("12-20");
    xVals.add("12-21"); xVals.add("12-22"); xVals.add("12-23"); xVals.add("12-24");
    */

    LineData data = new LineData(xVals, dataSets);
    // chart.setGridBackgroundColor(Color.BLACK);
    // chart.getLegend().setEnabled(false);
    chart.setData(data);
    chart.setDescription(getResources().getString(R.string.blood_pressure));
    chart.invalidate(); // refresh
  }
예제 #8
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();
    //            }
    //        });
  }
예제 #9
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_status, container, false);

    // TODO Need lot of design changes in chart
    // TODO Have to update LineChart with CombineChart to display LineChart with BarChart
    mChart = (LineChart) view.findViewById(R.id.chartInsight);
    mChart.setDescription("");
    mChart.setBackgroundColor(Color.WHITE);
    mChart.setDrawGridBackground(false);

    LineData d = new LineData();
    ArrayList<Entry> entries = new ArrayList<>();

    for (int index = 0; index < 12; index++) entries.add(new Entry(getRandom(25, 10), index));

    LineDataSet set = new LineDataSet(entries, "DataSet1");
    set.setColor(Color.rgb(240, 238, 70));
    set.setLineWidth(2.5f);
    set.setCircleColor(Color.rgb(240, 238, 70));
    set.setCircleSize(5f);
    set.setFillColor(Color.rgb(240, 238, 70));
    set.setDrawCubic(true);
    set.setDrawValues(true);
    set.setValueTextSize(10f);
    set.setValueTextColor(Color.rgb(240, 238, 70));

    for (int index = 0; index < 12; index++) entries.add(new Entry(getRandom(25, 10), index));

    LineDataSet set2 = new LineDataSet(entries, "DataSet2");
    set.setColor(Color.rgb(240, 238, 70));
    set.setLineWidth(2.5f);
    set.setCircleColor(Color.rgb(240, 238, 70));
    set.setCircleSize(5f);
    set.setFillColor(Color.rgb(240, 238, 70));
    set.setDrawCubic(true);
    set.setDrawValues(true);
    set.setValueTextSize(10f);
    set.setValueTextColor(Color.rgb(240, 238, 70));

    set.setAxisDependency(YAxis.AxisDependency.LEFT);

    d.addDataSet(set);
    d.addDataSet(set2);

    mChart.setData(d);
    mChart.setDescription("Fuel Insight");
    mChart.animateXY(2000, 2000);
    mChart.invalidate();

    //        String[] projection = { FuelContract.COLUMN_AMOUNT, FuelContract.COLUMN_ID };
    //        Cursor fuelData =
    // inflater.getContext().getContentResolver().query(FuelProvider.FUEL_CONTENT_URI, projection,
    // null, null, null);
    //        while (fuelData.getCount()!=0) {
    //            fuelData.moveToNext();
    //            Log.i("FuelData", "ID: " + fuelData.getString(1) + "  Amount: " +
    // fuelData.getString(0));
    //        }
    return view;
  }