-
-
Notifications
You must be signed in to change notification settings - Fork 9k
Expand file tree
/
Copy pathSineCosineFragment.java
More file actions
76 lines (55 loc) · 2.23 KB
/
SineCosineFragment.java
File metadata and controls
76 lines (55 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.xxmassdeveloper.mpchartexample.fragments;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.xxmassdeveloper.mpchartexample.R;
public class SineCosineFragment extends SimpleFragment {
@NonNull
public static Fragment newInstance() {
return new SineCosineFragment();
}
@SuppressWarnings("FieldCanBeLocal")
private LineChart chart;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag_simple_line, container, false);
chart = v.findViewById(R.id.lineChart1);
chart.getDescription().setEnabled(false);
chart.setDrawGridBackground(false);
chart.setData(generateLineData());
chart.animateX(3000);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");
Legend l = chart.getLegend();
l.setTypeface(tf);
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setTypeface(tf);
leftAxis.setAxisMaximum(1.2f);
leftAxis.setAxisMinimum(-1.2f);
chart.getAxisRight().setEnabled(false);
XAxis xAxis = chart.getXAxis();
xAxis.setEnabled(false);
chart.post(this::setupGradient);
return v;
}
private void setupGradient() {
Paint paint = chart.getRenderer().getPaintRender();
int height = chart.getHeight();
LinearGradient linGrad = new LinearGradient(0, 0, 0, height,
getResources().getColor(android.R.color.holo_blue_dark),
getResources().getColor(android.R.color.holo_green_dark),
Shader.TileMode.REPEAT);
paint.setShader(linGrad);
chart.invalidate();
}
}