blob: 7b0ea140f88c0c1141687dad37127d2b24ac66db [file] [log] [blame]
package com.xxmassdeveloper.mpchartexample;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.Toast;
import com.github.mikephil.charting.charts.RadarChart;
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.utils.Legend;
import com.github.mikephil.charting.utils.Legend.LegendPosition;
import com.github.mikephil.charting.utils.XLabels;
import com.github.mikephil.charting.utils.YLabels;
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);
mChart = (RadarChart) findViewById(R.id.chart1);
Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
mChart.setValueTypeface(tf);
mChart.setDescription("");
mChart.setWebLineWidth(1.5f);
mChart.setWebLineWidthInner(0.75f);
mChart.setWebAlpha(100);
mChart.setDrawYValues(false);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
// define an offset to change the original position of the marker
// (optional)
mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
// set the marker to the chart
mChart.setMarkerView(mv);
setData();
XLabels xl = mChart.getXLabels();
xl.setTypeface(tf);
xl.setTextSize(9f);
YLabels yl = mChart.getYLabels();
yl.setTypeface(tf);
yl.setLabelCount(5);
yl.setTextSize(9f);
// mChart.animateXY(1500, 1500);
Legend l = mChart.getLegend();
l.setPosition(LegendPosition.RIGHT_OF_CHART);
l.setTypeface(tf);
l.setXEntrySpace(7f);
l.setYEntrySpace(5f);
}
@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: {
if (mChart.isDrawYValuesEnabled())
mChart.setDrawYValues(false);
else
mChart.setDrawYValues(true);
mChart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if (mChart.isHighlightEnabled())
mChart.setHighlightEnabled(false);
else
mChart.setHighlightEnabled(true);
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<RadarDataSet> sets = (ArrayList<RadarDataSet>) mChart.getDataCurrent()
.getDataSets();
for (RadarDataSet set : sets) {
if (set.isDrawFilledEnabled())
set.setDrawFilled(false);
else
set.setDrawFilled(true);
}
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: {
if (mChart.isDrawXLabelsEnabled())
mChart.setDrawXLabels(false);
else
mChart.setDrawXLabels(true);
mChart.invalidate();
break;
}
case R.id.actionToggleYLabels: {
if (mChart.isDrawYLabelsEnabled())
mChart.setDrawYLabels(false);
else
mChart.setDrawYLabels(true);
mChart.invalidate();
break;
}
case R.id.actionToggleSpin: {
mChart.spin(2000, mChart.getRotationAngle(), mChart.getRotationAngle() + 360);
break;
}
}
return true;
}
private String[] mParties = new String[] {
"Party A", "Party B", "Party C", "Party D", "Party E", "Party F", "Party G", "Party H",
"Party I"
};
public void setData() {
float mult = 150;
int cnt = 9;
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++) {
yVals1.add(new Entry((float) (Math.random() * mult) + mult / 2, i));
}
for (int i = 0; i < cnt; i++) {
yVals2.add(new Entry((float) (Math.random() * mult) + mult / 2, i));
}
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < cnt; i++)
xVals.add(mParties[i % mParties.length]);
RadarDataSet set1 = new RadarDataSet(yVals1, "Set 1");
set1.setColor(getResources().getColor(R.color.vordiplom_1));
set1.setDrawFilled(true);
set1.setLineWidth(2f);
RadarDataSet set2 = new RadarDataSet(yVals2, "Set 2");
set2.setColor(getResources().getColor(R.color.vordiplom_5));
set2.setDrawFilled(true);
set2.setLineWidth(2f);
ArrayList<RadarDataSet> sets = new ArrayList<RadarDataSet>();
sets.add(set1);
sets.add(set2);
RadarData data = new RadarData(xVals, sets);
mChart.setData(data);
// undo all highlights
mChart.highlightValues(null);
mChart.invalidate();
}
}