use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.
the class RealtimeLineChartActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_realtime_linechart);
mChart = (LineChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
// enable description text
mChart.getDescription().setEnabled(true);
// enable touch gestures
mChart.setTouchEnabled(true);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setDrawGridBackground(false);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(true);
// set an alternative background color
mChart.setBackgroundColor(Color.LTGRAY);
LineData data = new LineData();
data.setValueTextColor(Color.WHITE);
// add empty data
mChart.setData(data);
// get the legend (only possible after setting data)
Legend l = mChart.getLegend();
// modify the legend ...
l.setForm(LegendForm.LINE);
l.setTypeface(mTfLight);
l.setTextColor(Color.WHITE);
XAxis xl = mChart.getXAxis();
xl.setTypeface(mTfLight);
xl.setTextColor(Color.WHITE);
xl.setDrawGridLines(false);
xl.setAvoidFirstLastClipping(true);
xl.setEnabled(true);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(mTfLight);
leftAxis.setTextColor(Color.WHITE);
leftAxis.setAxisMaximum(100f);
leftAxis.setAxisMinimum(0f);
leftAxis.setDrawGridLines(true);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setEnabled(false);
}
use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.
the class PieChartItem method getView.
@Override
public View getView(int position, View convertView, Context c) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(c).inflate(R.layout.list_item_piechart, null);
holder.chart = (PieChart) convertView.findViewById(R.id.chart);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// apply styling
holder.chart.getDescription().setEnabled(false);
holder.chart.setHoleRadius(52f);
holder.chart.setTransparentCircleRadius(57f);
holder.chart.setCenterText(mCenterText);
holder.chart.setCenterTextTypeface(mTf);
holder.chart.setCenterTextSize(9f);
holder.chart.setUsePercentValues(true);
holder.chart.setExtraOffsets(5, 10, 50, 10);
mChartData.setValueFormatter(new PercentFormatter());
mChartData.setValueTypeface(mTf);
mChartData.setValueTextSize(11f);
mChartData.setValueTextColor(Color.WHITE);
// set data
holder.chart.setData((PieData) mChartData);
Legend l = holder.chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(false);
l.setYEntrySpace(0f);
l.setYOffset(0f);
// do not forget to refresh the chart
// holder.chart.invalidate();
holder.chart.animateY(900);
return convertView;
}
use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.
the class PieChartFrag method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag_simple_pie, container, false);
mChart = (PieChart) v.findViewById(R.id.pieChart1);
mChart.getDescription().setEnabled(false);
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Light.ttf");
mChart.setCenterTextTypeface(tf);
mChart.setCenterText(generateCenterText());
mChart.setCenterTextSize(10f);
mChart.setCenterTextTypeface(tf);
// radius of the center hole in percent of maximum radius
mChart.setHoleRadius(45f);
mChart.setTransparentCircleRadius(50f);
Legend l = mChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(false);
mChart.setData(generatePieData());
return v;
}
use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.
the class ScatterChartFrag method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag_simple_scatter, container, false);
mChart = (ScatterChart) v.findViewById(R.id.scatterChart1);
mChart.getDescription().setEnabled(false);
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Light.ttf");
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
// For bounds control
mv.setChartView(mChart);
mChart.setMarker(mv);
mChart.setDrawGridBackground(false);
mChart.setData(generateScatterData(6, 10000, 200));
XAxis xAxis = mChart.getXAxis();
xAxis.setEnabled(true);
xAxis.setPosition(XAxisPosition.BOTTOM);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(tf);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setTypeface(tf);
rightAxis.setDrawGridLines(false);
Legend l = mChart.getLegend();
l.setWordWrapEnabled(true);
l.setTypeface(tf);
l.setFormSize(14f);
l.setTextSize(9f);
// increase the space between legend & bottom and legend & content
l.setYOffset(13f);
mChart.setExtraBottomOffset(16f);
return v;
}
use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.
the class SineCosineFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag_simple_line, container, false);
mChart = (LineChart) v.findViewById(R.id.lineChart1);
mChart.getDescription().setEnabled(false);
mChart.setDrawGridBackground(false);
mChart.setData(generateLineData());
mChart.animateX(3000);
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Light.ttf");
Legend l = mChart.getLegend();
l.setTypeface(tf);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(tf);
leftAxis.setAxisMaximum(1.2f);
leftAxis.setAxisMinimum(-1.2f);
mChart.getAxisRight().setEnabled(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setEnabled(false);
return v;
}
Aggregations