use of com.xxmassdeveloper.mpchartexample.custom.MyMarkerView in project MPAndroidChart by PhilJay.
the class LineChartActivity1 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_linechart);
setTitle("LineChartActivity1");
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
seekBarX = findViewById(R.id.seekBar1);
seekBarX.setOnSeekBarChangeListener(this);
seekBarY = findViewById(R.id.seekBar2);
seekBarY.setMax(180);
seekBarY.setOnSeekBarChangeListener(this);
{
// // Chart Style // //
chart = findViewById(R.id.chart1);
// background color
chart.setBackgroundColor(Color.WHITE);
// disable description text
chart.getDescription().setEnabled(false);
// enable touch gestures
chart.setTouchEnabled(true);
// set listeners
chart.setOnChartValueSelectedListener(this);
chart.setDrawGridBackground(false);
// create marker to display box when values are selected
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
// Set the marker to the chart
mv.setChartView(chart);
chart.setMarker(mv);
// enable scaling and dragging
chart.setDragEnabled(true);
chart.setScaleEnabled(true);
// chart.setScaleXEnabled(true);
// chart.setScaleYEnabled(true);
// force pinch zoom along both axis
chart.setPinchZoom(true);
}
XAxis xAxis;
{
// // X-Axis Style // //
xAxis = chart.getXAxis();
// vertical grid lines
xAxis.enableGridDashedLine(10f, 10f, 0f);
}
YAxis yAxis;
{
// // Y-Axis Style // //
yAxis = chart.getAxisLeft();
// disable dual axis (only use LEFT axis)
chart.getAxisRight().setEnabled(false);
// horizontal grid lines
yAxis.enableGridDashedLine(10f, 10f, 0f);
// axis range
yAxis.setAxisMaximum(200f);
yAxis.setAxisMinimum(-50f);
}
{
// // Create Limit Lines // //
LimitLine llXAxis = new LimitLine(9f, "Index 10");
llXAxis.setLineWidth(4f);
llXAxis.enableDashedLine(10f, 10f, 0f);
llXAxis.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
llXAxis.setTextSize(10f);
llXAxis.setTypeface(tfRegular);
LimitLine ll1 = new LimitLine(150f, "Upper Limit");
ll1.setLineWidth(4f);
ll1.enableDashedLine(10f, 10f, 0f);
ll1.setLabelPosition(LimitLabelPosition.RIGHT_TOP);
ll1.setTextSize(10f);
ll1.setTypeface(tfRegular);
LimitLine ll2 = new LimitLine(-30f, "Lower Limit");
ll2.setLineWidth(4f);
ll2.enableDashedLine(10f, 10f, 0f);
ll2.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
ll2.setTextSize(10f);
ll2.setTypeface(tfRegular);
// draw limit lines behind data instead of on top
yAxis.setDrawLimitLinesBehindData(true);
xAxis.setDrawLimitLinesBehindData(true);
// add limit lines
yAxis.addLimitLine(ll1);
yAxis.addLimitLine(ll2);
// xAxis.addLimitLine(llXAxis);
}
// add data
seekBarX.setProgress(45);
seekBarY.setProgress(180);
setData(45, 180);
// draw points over time
chart.animateX(1500);
// get the legend (only possible after setting data)
Legend l = chart.getLegend();
// draw legend entries as lines
l.setForm(LegendForm.LINE);
}
use of com.xxmassdeveloper.mpchartexample.custom.MyMarkerView in project MPAndroidChart by PhilJay.
the class InvertedLineChartActivity 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_linechart);
setTitle("InvertedLineChartActivity");
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
seekBarX = findViewById(R.id.seekBar1);
seekBarY = findViewById(R.id.seekBar2);
seekBarY.setOnSeekBarChangeListener(this);
seekBarX.setOnSeekBarChangeListener(this);
chart = findViewById(R.id.chart1);
chart.setOnChartValueSelectedListener(this);
chart.setDrawGridBackground(false);
// no description text
chart.getDescription().setEnabled(false);
// enable touch gestures
chart.setTouchEnabled(true);
// enable scaling and dragging
chart.setDragEnabled(true);
chart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
chart.setPinchZoom(true);
// set an alternative background color
// chart.setBackgroundColor(Color.GRAY);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
// For bounds control
mv.setChartView(chart);
// Set the marker to the chart
chart.setMarker(mv);
XAxis xl = chart.getXAxis();
xl.setAvoidFirstLastClipping(true);
xl.setAxisMinimum(0f);
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setInverted(true);
// this replaces setStartAtZero(true)
leftAxis.setAxisMinimum(0f);
YAxis rightAxis = chart.getAxisRight();
rightAxis.setEnabled(false);
// add data
seekBarX.setProgress(25);
seekBarY.setProgress(50);
// // restrain the maximum scale-out factor
// chart.setScaleMinima(3f, 3f);
//
// // center the view to a specific position inside the chart
// chart.centerViewPort(10, 50);
// get the legend (only possible after setting data)
Legend l = chart.getLegend();
// modify the legend ...
l.setForm(LegendForm.LINE);
// don't forget to refresh the drawing
chart.invalidate();
}
use of com.xxmassdeveloper.mpchartexample.custom.MyMarkerView in project MPAndroidChart by PhilJay.
the class BarChartActivityMultiDataset 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_barchart);
setTitle("BarChartActivityMultiDataset");
tvX = findViewById(R.id.tvXMax);
tvX.setTextSize(10);
tvY = findViewById(R.id.tvYMax);
seekBarX = findViewById(R.id.seekBar1);
seekBarX.setMax(50);
seekBarX.setOnSeekBarChangeListener(this);
seekBarY = findViewById(R.id.seekBar2);
seekBarY.setOnSeekBarChangeListener(this);
chart = findViewById(R.id.chart1);
chart.setOnChartValueSelectedListener(this);
chart.getDescription().setEnabled(false);
// chart.setDrawBorders(true);
// scaling can now only be done on x- and y-axis separately
chart.setPinchZoom(false);
chart.setDrawBarShadow(false);
chart.setDrawGridBackground(false);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
// For bounds control
mv.setChartView(chart);
// Set the marker to the chart
chart.setMarker(mv);
seekBarX.setProgress(10);
seekBarY.setProgress(100);
Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(true);
l.setTypeface(tfLight);
l.setYOffset(0f);
l.setXOffset(10f);
l.setYEntrySpace(0f);
l.setTextSize(8f);
XAxis xAxis = chart.getXAxis();
xAxis.setTypeface(tfLight);
xAxis.setGranularity(1f);
xAxis.setCenterAxisLabels(true);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return String.valueOf((int) value);
}
});
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setTypeface(tfLight);
leftAxis.setValueFormatter(new LargeValueFormatter());
leftAxis.setDrawGridLines(false);
leftAxis.setSpaceTop(35f);
// this replaces setStartAtZero(true)
leftAxis.setAxisMinimum(0f);
chart.getAxisRight().setEnabled(false);
}
use of com.xxmassdeveloper.mpchartexample.custom.MyMarkerView in project MPAndroidChart by PhilJay.
the class BarChartFrag method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag_simple_bar, container, false);
// create a new chart object
chart = new BarChart(getActivity());
chart.getDescription().setEnabled(false);
chart.setOnChartGestureListener(this);
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
// For bounds control
mv.setChartView(chart);
chart.setMarker(mv);
chart.setDrawGridBackground(false);
chart.setDrawBarShadow(false);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");
chart.setData(generateBarData(1, 20000, 12));
Legend l = chart.getLegend();
l.setTypeface(tf);
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setTypeface(tf);
// this replaces setStartAtZero(true)
leftAxis.setAxisMinimum(0f);
chart.getAxisRight().setEnabled(false);
XAxis xAxis = chart.getXAxis();
xAxis.setEnabled(false);
// programmatically add the chart
FrameLayout parent = v.findViewById(R.id.parentLayout);
parent.addView(chart);
return v;
}
use of com.xxmassdeveloper.mpchartexample.custom.MyMarkerView in project MPAndroidChart by PhilJay.
the class ScatterChartFrag method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag_simple_scatter, container, false);
chart = v.findViewById(R.id.scatterChart1);
chart.getDescription().setEnabled(false);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
// For bounds control
mv.setChartView(chart);
chart.setMarker(mv);
chart.setDrawGridBackground(false);
chart.setData(generateScatterData(6, 10000, 200));
XAxis xAxis = chart.getXAxis();
xAxis.setEnabled(true);
xAxis.setPosition(XAxisPosition.BOTTOM);
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setTypeface(tf);
YAxis rightAxis = chart.getAxisRight();
rightAxis.setTypeface(tf);
rightAxis.setDrawGridLines(false);
Legend l = chart.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);
chart.setExtraBottomOffset(16f);
return v;
}
Aggregations