Search in sources :

Example 21 with Legend

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);
}
Also used : LineData(com.github.mikephil.charting.data.LineData) Legend(com.github.mikephil.charting.components.Legend) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 22 with Legend

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;
}
Also used : PercentFormatter(com.github.mikephil.charting.formatter.PercentFormatter) Legend(com.github.mikephil.charting.components.Legend)

Example 23 with Legend

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;
}
Also used : Legend(com.github.mikephil.charting.components.Legend) Typeface(android.graphics.Typeface) View(android.view.View)

Example 24 with Legend

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;
}
Also used : Legend(com.github.mikephil.charting.components.Legend) Typeface(android.graphics.Typeface) View(android.view.View) MyMarkerView(com.xxmassdeveloper.mpchartexample.custom.MyMarkerView) MyMarkerView(com.xxmassdeveloper.mpchartexample.custom.MyMarkerView) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 25 with Legend

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;
}
Also used : Legend(com.github.mikephil.charting.components.Legend) Typeface(android.graphics.Typeface) View(android.view.View) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Aggregations

Legend (com.github.mikephil.charting.components.Legend)31 XAxis (com.github.mikephil.charting.components.XAxis)21 YAxis (com.github.mikephil.charting.components.YAxis)19 Typeface (android.graphics.Typeface)7 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)6 View (android.view.View)5 AxisBase (com.github.mikephil.charting.components.AxisBase)5 MyMarkerView (com.xxmassdeveloper.mpchartexample.custom.MyMarkerView)5 ArrayList (java.util.ArrayList)3 Paint (android.graphics.Paint)2 LineData (com.github.mikephil.charting.data.LineData)2 LineDataSet (com.github.mikephil.charting.data.LineDataSet)2 MyAxisValueFormatter (com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter)2 ValueAnimator (android.animation.ValueAnimator)1 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)1 DashPathEffect (android.graphics.DashPathEffect)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 ChartAnimator (com.github.mikephil.charting.animation.ChartAnimator)1 BarChart (com.github.mikephil.charting.charts.BarChart)1