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;
  }
Example #2
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;
  }