Example #1
0
 public void styleLineChart(LineChart chart) {
   chart.setGridBackgroundColor(0x00000000);
   chart.getAxisRight().setDrawLabels(false);
   chart.getXAxis().setDrawAxisLine(false);
   chart.getXAxis().setDrawGridLines(false);
   chart.getXAxis().setAvoidFirstLastClipping(true);
   chart.getLegend().setEnabled(false);
   chart.getAxisLeft().setDrawAxisLine(false);
   chart.getAxisRight().setDrawAxisLine(false);
   chart.invalidate();
 }
Example #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 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
  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;
  }
Example #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();
    //            }
    //        });
  }