| |
| package com.xxmassdeveloper.mpchartexample; |
| |
| import android.graphics.Color; |
| import android.os.Bundle; |
| import android.view.Menu; |
| import android.view.MenuItem; |
| import android.view.WindowManager; |
| import android.widget.TextView; |
| import android.widget.Toast; |
| |
| import com.github.mikephil.charting.animation.Easing; |
| import com.github.mikephil.charting.charts.RadarChart; |
| import com.github.mikephil.charting.components.AxisBase; |
| import com.github.mikephil.charting.components.Legend; |
| import com.github.mikephil.charting.components.Legend.LegendPosition; |
| import com.github.mikephil.charting.components.MarkerView; |
| import com.github.mikephil.charting.components.XAxis; |
| import com.github.mikephil.charting.components.YAxis; |
| import com.github.mikephil.charting.data.Entry; |
| import com.github.mikephil.charting.data.RadarData; |
| import com.github.mikephil.charting.data.RadarDataSet; |
| import com.github.mikephil.charting.formatter.AxisValueFormatter; |
| import com.github.mikephil.charting.interfaces.datasets.IDataSet; |
| import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet; |
| import com.xxmassdeveloper.mpchartexample.custom.RadarMarkerView; |
| import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase; |
| |
| import java.util.ArrayList; |
| |
| public class RadarChartActivitry extends DemoBase { |
| |
| private RadarChart mChart; |
| |
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, |
| WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| setContentView(R.layout.activity_radarchart_noseekbar); |
| |
| TextView tv = (TextView) findViewById(R.id.textView); |
| tv.setTypeface(mTfLight); |
| tv.setTextColor(Color.WHITE); |
| tv.setBackgroundColor(Color.rgb(60, 65, 82)); |
| |
| mChart = (RadarChart) findViewById(R.id.chart1); |
| mChart.setBackgroundColor(Color.rgb(60, 65, 82)); |
| |
| mChart.setDescription(""); |
| |
| mChart.setWebLineWidth(1f); |
| mChart.setWebColor(Color.LTGRAY); |
| mChart.setWebLineWidthInner(1f); |
| mChart.setWebColorInner(Color.LTGRAY); |
| mChart.setWebAlpha(100); |
| |
| // create a custom MarkerView (extend MarkerView) and specify the layout |
| // to use for it |
| MarkerView mv = new RadarMarkerView(this, R.layout.radar_markerview); |
| |
| // set the marker to the chart |
| mChart.setMarkerView(mv); |
| |
| setData(); |
| |
| mChart.animateXY( |
| 1400, 1400, |
| Easing.EasingOption.EaseInOutQuad, |
| Easing.EasingOption.EaseInOutQuad); |
| |
| XAxis xAxis = mChart.getXAxis(); |
| xAxis.setTypeface(mTfLight); |
| xAxis.setTextSize(9f); |
| xAxis.setYOffset(0f); |
| xAxis.setXOffset(0f); |
| xAxis.setValueFormatter(new AxisValueFormatter() { |
| |
| private String[] mActivities = new String[]{"Burger", "Steak", "Salad", "Pasta", "Pizza"}; |
| @Override |
| public String getFormattedValue(float value, AxisBase axis) { |
| return mActivities[(int) value % mActivities.length]; |
| } |
| |
| @Override |
| public int getDecimalDigits() { |
| return 0; |
| } |
| }); |
| xAxis.setTextColor(Color.WHITE); |
| |
| YAxis yAxis = mChart.getYAxis(); |
| yAxis.setTypeface(mTfLight); |
| yAxis.setLabelCount(5, false); |
| yAxis.setTextSize(9f); |
| yAxis.setAxisMinValue(0f); |
| yAxis.setAxisMaxValue(80f); |
| yAxis.setDrawLabels(false); |
| |
| Legend l = mChart.getLegend(); |
| l.setPosition(LegendPosition.ABOVE_CHART_CENTER); |
| l.setTypeface(mTfLight); |
| l.setXEntrySpace(7f); |
| l.setYEntrySpace(5f); |
| l.setTextColor(Color.WHITE); |
| } |
| |
| @Override |
| public boolean onCreateOptionsMenu(Menu menu) { |
| getMenuInflater().inflate(R.menu.radar, menu); |
| return true; |
| } |
| |
| @Override |
| public boolean onOptionsItemSelected(MenuItem item) { |
| |
| switch (item.getItemId()) { |
| case R.id.actionToggleValues: { |
| for (IDataSet<?> set : mChart.getData().getDataSets()) |
| set.setDrawValues(!set.isDrawValuesEnabled()); |
| |
| mChart.invalidate(); |
| break; |
| } |
| case R.id.actionToggleHighlight: { |
| if (mChart.getData() != null) { |
| mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled()); |
| mChart.invalidate(); |
| } |
| break; |
| } |
| case R.id.actionToggleRotate: { |
| if (mChart.isRotationEnabled()) |
| mChart.setRotationEnabled(false); |
| else |
| mChart.setRotationEnabled(true); |
| mChart.invalidate(); |
| break; |
| } |
| case R.id.actionToggleFilled: { |
| |
| ArrayList<IRadarDataSet> sets = (ArrayList<IRadarDataSet>) mChart.getData() |
| .getDataSets(); |
| |
| for (IRadarDataSet set : sets) { |
| if (set.isDrawFilledEnabled()) |
| set.setDrawFilled(false); |
| else |
| set.setDrawFilled(true); |
| } |
| mChart.invalidate(); |
| break; |
| } |
| case R.id.actionToggleHighlightCircle: { |
| |
| ArrayList<IRadarDataSet> sets = (ArrayList<IRadarDataSet>) mChart.getData() |
| .getDataSets(); |
| |
| for (IRadarDataSet set : sets) { |
| set.setDrawHighlightCircleEnabled(!set.isDrawHighlightCircleEnabled()); |
| } |
| mChart.invalidate(); |
| break; |
| } |
| case R.id.actionSave: { |
| if (mChart.saveToPath("title" + System.currentTimeMillis(), "")) { |
| Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!", |
| Toast.LENGTH_SHORT).show(); |
| } else |
| Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT) |
| .show(); |
| break; |
| } |
| case R.id.actionToggleXLabels: { |
| mChart.getXAxis().setEnabled(!mChart.getXAxis().isEnabled()); |
| mChart.notifyDataSetChanged(); |
| mChart.invalidate(); |
| break; |
| } |
| case R.id.actionToggleYLabels: { |
| |
| mChart.getYAxis().setEnabled(!mChart.getYAxis().isEnabled()); |
| mChart.invalidate(); |
| break; |
| } |
| case R.id.animateX: { |
| mChart.animateX(1400); |
| break; |
| } |
| case R.id.animateY: { |
| mChart.animateY(1400); |
| break; |
| } |
| case R.id.animateXY: { |
| mChart.animateXY(1400, 1400); |
| break; |
| } |
| case R.id.actionToggleSpin: { |
| mChart.spin(2000, mChart.getRotationAngle(), mChart.getRotationAngle() + 360, Easing.EasingOption |
| .EaseInCubic); |
| break; |
| } |
| } |
| return true; |
| } |
| |
| public void setData() { |
| |
| float mult = 80; |
| float min = 20; |
| int cnt = 5; |
| |
| ArrayList<Entry> yVals1 = new ArrayList<Entry>(); |
| ArrayList<Entry> yVals2 = new ArrayList<Entry>(); |
| |
| // IMPORTANT: In a PieChart, no values (Entry) should have the same |
| // xIndex (even if from different DataSets), since no values can be |
| // drawn above each other. |
| for (int i = 0; i < cnt; i++) { |
| float val = (float) (Math.random() * mult) + min; |
| yVals1.add(new Entry(i, val)); |
| } |
| |
| for (int i = 0; i < cnt; i++) { |
| float val = (float) (Math.random() * mult) + min; |
| yVals2.add(new Entry(i, val)); |
| } |
| |
| RadarDataSet set1 = new RadarDataSet(yVals1, "Last Week"); |
| set1.setColor(Color.rgb(103, 110, 129)); |
| set1.setFillColor(Color.rgb(103, 110, 129)); |
| set1.setDrawFilled(true); |
| set1.setFillAlpha(180); |
| set1.setLineWidth(2f); |
| set1.setDrawHighlightCircleEnabled(true); |
| set1.setDrawHighlightIndicators(false); |
| |
| RadarDataSet set2 = new RadarDataSet(yVals2, "This Week"); |
| set2.setColor(Color.rgb(121, 162, 175)); |
| set2.setFillColor(Color.rgb(121, 162, 175)); |
| set2.setDrawFilled(true); |
| set2.setFillAlpha(180); |
| set2.setLineWidth(2f); |
| set2.setDrawHighlightCircleEnabled(true); |
| set2.setDrawHighlightIndicators(false); |
| |
| ArrayList<IRadarDataSet> sets = new ArrayList<IRadarDataSet>(); |
| sets.add(set1); |
| sets.add(set2); |
| |
| RadarData data = new RadarData(sets); |
| data.setValueTypeface(mTfLight); |
| data.setValueTextSize(8f); |
| data.setDrawValues(false); |
| data.setValueTextColor(Color.WHITE); |
| |
| mChart.setData(data); |
| mChart.invalidate(); |
| } |
| } |