Brush up radarchart example
This commit is contained in:
parent
f39d8911d3
commit
6d39afa028
5 changed files with 86 additions and 4 deletions
BIN
MPChartExample/res/drawable-nodpi/radar_marker.png
Normal file
BIN
MPChartExample/res/drawable-nodpi/radar_marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.5 KiB |
|
@ -4,11 +4,10 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="0.5"
|
||||
android:layout_weight="0.6"
|
||||
android:gravity="center"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="YOUR PREFERENCES"
|
||||
|
|
23
MPChartExample/res/layout/radar_markerview.xml
Normal file
23
MPChartExample/res/layout/radar_markerview.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="55dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="@drawable/radar_marker" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="3dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:text=""
|
||||
android:textSize="10dp"
|
||||
android:textColor="@android:color/white"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -15,6 +15,7 @@ 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;
|
||||
|
@ -25,6 +26,7 @@ import com.github.mikephil.charting.interfaces.datasets.IDataSet;
|
|||
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RadarMarkerView;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -41,7 +43,7 @@ public class RadarChartActivitry extends DemoBase {
|
|||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_radarchart_noseekbar);
|
||||
|
||||
tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
|
||||
tf = Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf");
|
||||
|
||||
TextView tv = (TextView) findViewById(R.id.textView);
|
||||
tv.setTypeface(tf);
|
||||
|
@ -56,11 +58,12 @@ public class RadarChartActivitry extends DemoBase {
|
|||
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
|
||||
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
|
||||
MarkerView mv = new RadarMarkerView(this, R.layout.radar_markerview);
|
||||
|
||||
// set the marker to the chart
|
||||
mChart.setMarkerView(mv);
|
||||
|
@ -97,6 +100,7 @@ public class RadarChartActivitry extends DemoBase {
|
|||
yAxis.setLabelCount(5, false);
|
||||
yAxis.setTextSize(9f);
|
||||
yAxis.setAxisMinValue(0f);
|
||||
yAxis.setAxisMaxValue(80f);
|
||||
yAxis.setDrawLabels(false);
|
||||
|
||||
Legend l = mChart.getLegend();
|
||||
|
@ -234,6 +238,8 @@ public class RadarChartActivitry extends DemoBase {
|
|||
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));
|
||||
|
@ -241,6 +247,8 @@ public class RadarChartActivitry extends DemoBase {
|
|||
set2.setDrawFilled(true);
|
||||
set2.setFillAlpha(180);
|
||||
set2.setLineWidth(2f);
|
||||
set2.setDrawHighlightCircleEnabled(true);
|
||||
set2.setDrawHighlightIndicators(false);
|
||||
|
||||
ArrayList<IRadarDataSet> sets = new ArrayList<IRadarDataSet>();
|
||||
sets.add(set1);
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
|
||||
package com.xxmassdeveloper.mpchartexample.custom;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.mikephil.charting.components.MarkerView;
|
||||
import com.github.mikephil.charting.data.CandleEntry;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.utils.Utils;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* Custom implementation of the MarkerView.
|
||||
*
|
||||
* @author Philipp Jahoda
|
||||
*/
|
||||
public class RadarMarkerView extends MarkerView {
|
||||
|
||||
private TextView tvContent;
|
||||
private DecimalFormat format = new DecimalFormat("##0");
|
||||
|
||||
public RadarMarkerView(Context context, int layoutResource) {
|
||||
super(context, layoutResource);
|
||||
|
||||
tvContent = (TextView) findViewById(R.id.tvContent);
|
||||
tvContent.setTypeface(Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf"));
|
||||
}
|
||||
|
||||
// callbacks everytime the MarkerView is redrawn, can be used to update the
|
||||
// content (user-interface)
|
||||
@Override
|
||||
public void refreshContent(Entry e, Highlight highlight) {
|
||||
tvContent.setText(format.format(e.getY()) + " %");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXOffset(float xpos) {
|
||||
// this will center the marker-view horizontally
|
||||
return -(getWidth() / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getYOffset(float ypos) {
|
||||
// this will cause the marker-view to be above the selected yValue
|
||||
return -getHeight()-10;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue