Java Code Examples for com.github.mikephil.charting.charts.PieChart#setOnChartValueSelectedListener()

The following examples show how to use com.github.mikephil.charting.charts.PieChart#setOnChartValueSelectedListener() . 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: StatisticViewHolder.java    From BrainPhaser with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Applies a most played / failed / succeeded chart to the chart in the mItemView view
 *
 * @param type the statistic type of the chart to be applied
 */
public void applyMostPlayedChart(StatisticType type) {
    //Apply chart
    PieChart chart = (PieChart) mItemView.findViewById(R.id.statisticsChart);
    mShownChallenges = mStatisticsLogic.fillChart(chart, type);

    //Add chart selection listener
    chart.setOnChartValueSelectedListener(new ChartValueSelectedListener(this));

    //Select first entry
    if (chart.getData() != null) {
        chart.highlightValue(0, 0);
        TextView text = (TextView) mItemView.findViewById(R.id.challengeView);
        String question = mChallengeDataSource.getById(mShownChallenges.get(0)).getQuestion();

        if (text != null) text.setText(question);
    }

    TextView title = (TextView) mItemView.findViewById(R.id.titleView);
    if (title != null) title.setText(getTitle(type));
}
 
Example 2
Source File: ColorDetectionActivity.java    From FaceT with Mozilla Public License 2.0 5 votes vote down vote up
private void seteffect(PieChart colorPie) {

        colorPie.animateXY(2000, 2000, Easing.EasingOption.EaseInBounce, Easing.EasingOption.EaseInBounce);
        colorPie.invalidate();
        colorPie.setDrawHoleEnabled(true);
        colorPie.setExtraOffsets(10, 10, 10, 10);

        colorPie.setContentDescription("");
        colorPie.setDragDecelerationFrictionCoef(0.95f);
        colorPie.setDrawCenterText(true);

        colorPie.setRotationAngle(0);
        // enable rotation of the chart by touch
        colorPie.setRotationEnabled(true);
        colorPie.setHighlightPerTapEnabled(true);
        colorPie.setDrawHoleEnabled(true);
        colorPie.setHoleColor(Color.WHITE);

        //disable the label and description
        colorPie.getDescription().setEnabled(false);
        colorPie.getLegend().setEnabled(false);

        colorPie.setTransparentCircleColor(Color.WHITE);
        colorPie.setTransparentCircleAlpha(80);
        colorPie.setElevation(10f);
        colorPie.setHoleRadius(60f);
        colorPie.setTransparentCircleRadius(61f);

        // add a selection listener
        colorPie.setOnChartValueSelectedListener(this);

    }
 
Example 3
Source File: ProductDetailActivity.java    From FaceT with Mozilla Public License 2.0 5 votes vote down vote up
private void setEffectPieChart(PieChart colorPie) {

        colorPie.animateXY(1500, 1500, Easing.EasingOption.EaseInBounce, Easing.EasingOption.EaseInBounce);
        colorPie.invalidate();
        colorPie.setDrawHoleEnabled(true);
        colorPie.setExtraOffsets(10, 10, 10, 10);

        colorPie.setContentDescription("");
        colorPie.setDragDecelerationFrictionCoef(0.95f);
        colorPie.setDrawCenterText(true);

        colorPie.setRotationAngle(0);
        // enable rotation of the chart by touch
        colorPie.setRotationEnabled(true);
        colorPie.setHighlightPerTapEnabled(true);
        colorPie.setDrawHoleEnabled(true);
        colorPie.setHoleColor(Color.WHITE);
        colorPie.getLegend().setFormSize(10f);
        colorPie.getLegend().setFormToTextSpace(5f);

        //disable the label and description
        colorPie.getDescription().setEnabled(false);
        colorPie.getLegend().setEnabled(false);

        colorPie.setTransparentCircleColor(Color.WHITE);
        colorPie.setTransparentCircleAlpha(80);
        colorPie.setElevation(10f);
        colorPie.setHoleRadius(90f);
        colorPie.setTransparentCircleRadius(61f);

        // add a selection listener
        colorPie.setOnChartValueSelectedListener(this);

    }
 
Example 4
Source File: GraphicActivity.java    From ToDay with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_graphic);

    pieChart = (PieChart) findViewById(R.id.idPieChart);
    pieChart.setRotationEnabled(true);
    pieChart.setHoleRadius(25f);
    pieChart.setTransparentCircleAlpha(0);
    pieChart.setCenterText("Төлөвлөгөө");
    pieChart.setCenterTextSize(10);
    pieChart.setDrawEntryLabels(true);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    addDataSet();

    pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
        @Override
        public void onValueSelected(Entry e, Highlight h) {
            Log.d(TAG, "onValueSelected: Value select from chart.");
            Log.d(TAG, "onValueSelected: " + e.toString());
            Log.d(TAG, "onValueSelected: " + h.toString());

            int pos1 = e.toString().indexOf("(sum): ");
            String sales = e.toString().substring(pos1 + 7);

            for(int i = 0; i < yData.length; i++){
                if(yData[i] == Float.parseFloat(sales)){
                    pos1 = i;
                    break;
                }
            }
            String employee = xData[pos1 + 1];
            Toast.makeText(GraphicActivity.this, "Employee " + employee + "\n" + "Sales: $" + sales + "K", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onNothingSelected() {

        }
    });

 }
 
Example 5
Source File: PieChartActivity.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_piechart);

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

    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);

    mSeekBarY.setProgress(10);

    mSeekBarX.setOnSeekBarChangeListener(this);
    mSeekBarY.setOnSeekBarChangeListener(this);

    mChart = (PieChart) findViewById(R.id.chart1);
    mChart.setUsePercentValues(true);
    mChart.setDescription("");
    mChart.setExtraOffsets(5, 10, 5, 5);

    mChart.setDragDecelerationFrictionCoef(0.95f);

    tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

    mChart.setCenterTextTypeface(Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf"));
    mChart.setCenterText(generateCenterSpannableText());

    mChart.setDrawHoleEnabled(true);
    mChart.setHoleColor(Color.WHITE);

    mChart.setTransparentCircleColor(Color.WHITE);
    mChart.setTransparentCircleAlpha(110);

    mChart.setHoleRadius(58f);
    mChart.setTransparentCircleRadius(61f);

    mChart.setDrawCenterText(true);

    mChart.setRotationAngle(0);
    // enable rotation of the chart by touch
    mChart.setRotationEnabled(true);
    mChart.setHighlightPerTapEnabled(true);

    // mChart.setUnit(" €");
    // mChart.setDrawUnitsInChart(true);

    // add a selection listener
    mChart.setOnChartValueSelectedListener(this);

    setData(3, 100);

    mChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
    // mChart.spin(2000, 0, 360);

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.RIGHT_OF_CHART);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(0f);
    l.setYOffset(0f);
}