Exemple #1
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;
  }
  @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;
  }