• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xxmassdeveloper.mpchartexample.fragments;
2 
3 import android.graphics.Typeface;
4 import android.os.Bundle;
5 import androidx.annotation.NonNull;
6 import androidx.fragment.app.Fragment;
7 import android.view.LayoutInflater;
8 import android.view.View;
9 import android.view.ViewGroup;
10 
11 import com.github.mikephil.charting.charts.ScatterChart;
12 import com.github.mikephil.charting.components.Legend;
13 import com.github.mikephil.charting.components.XAxis;
14 import com.github.mikephil.charting.components.XAxis.XAxisPosition;
15 import com.github.mikephil.charting.components.YAxis;
16 import com.xxmassdeveloper.mpchartexample.R;
17 import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
18 
19 
20 public class ScatterChartFrag extends SimpleFragment {
21 
22     @NonNull
newInstance()23     public static Fragment newInstance() {
24         return new ScatterChartFrag();
25     }
26 
27     @SuppressWarnings("FieldCanBeLocal")
28     private ScatterChart chart;
29 
30     @Override
onCreateView(@onNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)31     public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
32         View v = inflater.inflate(R.layout.frag_simple_scatter, container, false);
33 
34         chart = v.findViewById(R.id.scatterChart1);
35         chart.getDescription().setEnabled(false);
36 
37         Typeface tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");
38 
39         MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
40         mv.setChartView(chart); // For bounds control
41         chart.setMarker(mv);
42 
43         chart.setDrawGridBackground(false);
44         chart.setData(generateScatterData(6, 10000, 200));
45 
46         XAxis xAxis = chart.getXAxis();
47         xAxis.setEnabled(true);
48         xAxis.setPosition(XAxisPosition.BOTTOM);
49 
50         YAxis leftAxis = chart.getAxisLeft();
51         leftAxis.setTypeface(tf);
52 
53         YAxis rightAxis = chart.getAxisRight();
54         rightAxis.setTypeface(tf);
55         rightAxis.setDrawGridLines(false);
56 
57         Legend l = chart.getLegend();
58         l.setWordWrapEnabled(true);
59         l.setTypeface(tf);
60         l.setFormSize(14f);
61         l.setTextSize(9f);
62 
63         // increase the space between legend & bottom and legend & content
64         l.setYOffset(13f);
65         chart.setExtraBottomOffset(16f);
66 
67         return v;
68     }
69 }
70