Search in sources :

Example 6 with BarDataSet

use of com.github.mikephil.charting.data.BarDataSet in project MPAndroidChart by PhilJay.

the class StackedBarActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.viewGithub:
            {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java"));
                startActivity(i);
                break;
            }
        case R.id.actionToggleValues:
            {
                List<IBarDataSet> sets = chart.getData().getDataSets();
                for (IBarDataSet iSet : sets) {
                    BarDataSet set = (BarDataSet) iSet;
                    set.setDrawValues(!set.isDrawValuesEnabled());
                }
                chart.invalidate();
                break;
            }
        case R.id.actionToggleIcons:
            {
                List<IBarDataSet> sets = chart.getData().getDataSets();
                for (IBarDataSet iSet : sets) {
                    BarDataSet set = (BarDataSet) iSet;
                    set.setDrawIcons(!set.isDrawIconsEnabled());
                }
                chart.invalidate();
                break;
            }
        case R.id.actionToggleHighlight:
            {
                if (chart.getData() != null) {
                    chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
                    chart.invalidate();
                }
                break;
            }
        case R.id.actionTogglePinch:
            {
                if (chart.isPinchZoomEnabled())
                    chart.setPinchZoom(false);
                else
                    chart.setPinchZoom(true);
                chart.invalidate();
                break;
            }
        case R.id.actionToggleAutoScaleMinMax:
            {
                chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
                chart.notifyDataSetChanged();
                break;
            }
        case R.id.actionToggleBarBorders:
            {
                for (IBarDataSet set : chart.getData().getDataSets()) ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
                chart.invalidate();
                break;
            }
        case R.id.animateX:
            {
                chart.animateX(2000);
                break;
            }
        case R.id.animateY:
            {
                chart.animateY(2000);
                break;
            }
        case R.id.animateXY:
            {
                chart.animateXY(2000, 2000);
                break;
            }
        case R.id.actionSave:
            {
                if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                    saveToGallery();
                } else {
                    requestStoragePermission(chart);
                }
                break;
            }
    }
    return true;
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) Intent(android.content.Intent) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with BarDataSet

use of com.github.mikephil.charting.data.BarDataSet in project MPAndroidChart by PhilJay.

the class BarChartActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.viewGithub:
            {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java"));
                startActivity(i);
                break;
            }
        case R.id.actionToggleValues:
            {
                for (IDataSet set : chart.getData().getDataSets()) set.setDrawValues(!set.isDrawValuesEnabled());
                chart.invalidate();
                break;
            }
        case R.id.actionToggleIcons:
            {
                for (IDataSet set : chart.getData().getDataSets()) set.setDrawIcons(!set.isDrawIconsEnabled());
                chart.invalidate();
                break;
            }
        case R.id.actionToggleHighlight:
            {
                if (chart.getData() != null) {
                    chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
                    chart.invalidate();
                }
                break;
            }
        case R.id.actionTogglePinch:
            {
                if (chart.isPinchZoomEnabled())
                    chart.setPinchZoom(false);
                else
                    chart.setPinchZoom(true);
                chart.invalidate();
                break;
            }
        case R.id.actionToggleAutoScaleMinMax:
            {
                chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
                chart.notifyDataSetChanged();
                break;
            }
        case R.id.actionToggleBarBorders:
            {
                for (IBarDataSet set : chart.getData().getDataSets()) ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
                chart.invalidate();
                break;
            }
        case R.id.animateX:
            {
                chart.animateX(2000);
                break;
            }
        case R.id.animateY:
            {
                chart.animateY(2000);
                break;
            }
        case R.id.animateXY:
            {
                chart.animateXY(2000, 2000);
                break;
            }
        case R.id.actionSave:
            {
                if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                    saveToGallery();
                } else {
                    requestStoragePermission(chart);
                }
                break;
            }
    }
    return true;
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) Intent(android.content.Intent) IDataSet(com.github.mikephil.charting.interfaces.datasets.IDataSet)

Example 8 with BarDataSet

use of com.github.mikephil.charting.data.BarDataSet in project MPAndroidChart by PhilJay.

the class BarChartActivitySinus method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.viewGithub:
            {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java"));
                startActivity(i);
                break;
            }
        case R.id.actionToggleValues:
            {
                for (IBarDataSet set : chart.getData().getDataSets()) set.setDrawValues(!set.isDrawValuesEnabled());
                chart.invalidate();
                break;
            }
        case R.id.actionToggleHighlight:
            {
                if (chart.getData() != null) {
                    chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
                    chart.invalidate();
                }
                break;
            }
        case R.id.actionTogglePinch:
            {
                if (chart.isPinchZoomEnabled())
                    chart.setPinchZoom(false);
                else
                    chart.setPinchZoom(true);
                chart.invalidate();
                break;
            }
        case R.id.actionToggleAutoScaleMinMax:
            {
                chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
                chart.notifyDataSetChanged();
                break;
            }
        case R.id.actionToggleBarBorders:
            {
                for (IBarDataSet set : chart.getData().getDataSets()) ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
                chart.invalidate();
                break;
            }
        case R.id.animateX:
            {
                chart.animateX(2000);
                break;
            }
        case R.id.animateY:
            {
                chart.animateY(2000);
                break;
            }
        case R.id.animateXY:
            {
                chart.animateXY(2000, 2000);
                break;
            }
        case R.id.actionSave:
            {
                if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                    saveToGallery();
                } else {
                    requestStoragePermission(chart);
                }
                break;
            }
    }
    return true;
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) Intent(android.content.Intent)

Example 9 with BarDataSet

use of com.github.mikephil.charting.data.BarDataSet in project MPAndroidChart by PhilJay.

the class BarChartActivitySinus method setData.

private void setData(int count) {
    ArrayList<BarEntry> entries = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        entries.add(data.get(i));
    }
    BarDataSet set;
    if (chart.getData() != null && chart.getData().getDataSetCount() > 0) {
        set = (BarDataSet) chart.getData().getDataSetByIndex(0);
        set.setValues(entries);
        chart.getData().notifyDataChanged();
        chart.notifyDataSetChanged();
    } else {
        set = new BarDataSet(entries, "Sinus Function");
        set.setColor(Color.rgb(240, 120, 124));
    }
    BarData data = new BarData(set);
    data.setValueTextSize(10f);
    data.setValueTypeface(tfLight);
    data.setDrawValues(false);
    data.setBarWidth(0.8f);
    chart.setData(data);
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) BarData(com.github.mikephil.charting.data.BarData) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 10 with BarDataSet

use of com.github.mikephil.charting.data.BarDataSet in project MPAndroidChart by PhilJay.

the class HorizontalBarChartActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.viewGithub:
            {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java"));
                startActivity(i);
                break;
            }
        case R.id.actionToggleValues:
            {
                List<IBarDataSet> sets = chart.getData().getDataSets();
                for (IBarDataSet iSet : sets) {
                    iSet.setDrawValues(!iSet.isDrawValuesEnabled());
                }
                chart.invalidate();
                break;
            }
        case R.id.actionToggleIcons:
            {
                List<IBarDataSet> sets = chart.getData().getDataSets();
                for (IBarDataSet iSet : sets) {
                    iSet.setDrawIcons(!iSet.isDrawIconsEnabled());
                }
                chart.invalidate();
                break;
            }
        case R.id.actionToggleHighlight:
            {
                if (chart.getData() != null) {
                    chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
                    chart.invalidate();
                }
                break;
            }
        case R.id.actionTogglePinch:
            {
                if (chart.isPinchZoomEnabled())
                    chart.setPinchZoom(false);
                else
                    chart.setPinchZoom(true);
                chart.invalidate();
                break;
            }
        case R.id.actionToggleAutoScaleMinMax:
            {
                chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled());
                chart.notifyDataSetChanged();
                break;
            }
        case R.id.actionToggleBarBorders:
            {
                for (IBarDataSet set : chart.getData().getDataSets()) ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
                chart.invalidate();
                break;
            }
        case R.id.animateX:
            {
                chart.animateX(2000);
                break;
            }
        case R.id.animateY:
            {
                chart.animateY(2000);
                break;
            }
        case R.id.animateXY:
            {
                chart.animateXY(2000, 2000);
                break;
            }
        case R.id.actionSave:
            {
                if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                    saveToGallery();
                } else {
                    requestStoragePermission(chart);
                }
                break;
            }
    }
    return true;
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) Intent(android.content.Intent) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

BarDataSet (com.github.mikephil.charting.data.BarDataSet)41 ArrayList (java.util.ArrayList)27 BarEntry (com.github.mikephil.charting.data.BarEntry)25 BarData (com.github.mikephil.charting.data.BarData)24 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)22 Intent (android.content.Intent)8 Paint (android.graphics.Paint)5 List (java.util.List)4 SuppressLint (android.annotation.SuppressLint)2 XAxis (com.github.mikephil.charting.components.XAxis)2 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)2 IDataSet (com.github.mikephil.charting.interfaces.datasets.IDataSet)2 Context (android.content.Context)1 Path (android.graphics.Path)1 PointF (android.graphics.PointF)1 RectF (android.graphics.RectF)1 BarChart (com.github.mikephil.charting.charts.BarChart)1 AxisBase (com.github.mikephil.charting.components.AxisBase)1 Legend (com.github.mikephil.charting.components.Legend)1 LimitLine (com.github.mikephil.charting.components.LimitLine)1