Java Code Examples for com.github.mikephil.charting.charts.BarChart#animateY()

The following examples show how to use com.github.mikephil.charting.charts.BarChart#animateY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Load the model and labels.
    try {
        classifier = new DigitClassifierModel(this);
    } catch (IOException e) {
        Log.e(TAG, "Failed to initialize an image classifier.", e);
    }
    //startBackgroundThread();

    setContentView(R.layout.activity_main);
    paintView = (FreeHandView) findViewById(R.id.paintView);
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);


    BarChart barChart = (BarChart) findViewById(R.id.barChart);
    barChart.animateY(3000);
    barChart.getXAxis().setEnabled(true);
    barChart.getAxisRight().setEnabled(false);
    barChart.getAxisLeft().setAxisMinimum(0.0f); // start at zero
    barChart.getAxisLeft().setAxisMaximum(1.0f); // the axis maximum is 100
    barChart.getDescription().setEnabled(false);
    barChart.getLegend().setEnabled(false);

    // the labels that should be drawn on the XAxis
    final String[] barLabels = new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

    IAxisValueFormatter formatter = new IAxisValueFormatter() {

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return barLabels[(int) value];
        }
    };

    barChart.getXAxis().setGranularity(0f); // minimum axis-step (interval) is 1
    barChart.getXAxis().setValueFormatter(formatter);
    barChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
    barChart.getXAxis().setTextSize(5f);

    BARENTRY = new ArrayList<>();
    initializeBARENTRY();

    Bardataset = new BarDataSet(BARENTRY, "project");

    BARDATA = new BarData(Bardataset);
    barChart.setData(BARDATA);


    paintView.init(metrics, classifier, barChart);


    Button resetButton = (Button) findViewById(R.id.resetButton);
    resetButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            paintView.clear();
        }
    });

}
 
Example 2
Source File: AnotherBarActivity.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_barchart);

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

    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarX.setOnSeekBarChangeListener(this);

    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mSeekBarY.setOnSeekBarChangeListener(this);

    mChart = (BarChart) findViewById(R.id.chart1);

    mChart.setDescription("");

    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    mChart.setMaxVisibleValueCount(60);

    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    mChart.setDrawBarShadow(false);
    mChart.setDrawGridBackground(false);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setSpaceBetweenLabels(0);
    xAxis.setDrawGridLines(false);
    
    mChart.getAxisLeft().setDrawGridLines(false);

    // setting data
    mSeekBarX.setProgress(10);
    mSeekBarY.setProgress(100);

    // add a nice and smooth animation
    mChart.animateY(2500);
    
    mChart.getLegend().setEnabled(false);

    // Legend l = mChart.getLegend();
    // l.setPosition(LegendPosition.BELOW_CHART_CENTER);
    // l.setFormSize(8f);
    // l.setFormToTextSpace(4f);
    // l.setXEntrySpace(6f);

    // mChart.setDrawLegend(false);
}