Search in sources :

Example 51 with YAxis

use of com.github.mikephil.charting.components.YAxis 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;
}
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 52 with YAxis

use of com.github.mikephil.charting.components.YAxis in project MPAndroidChart by PhilJay.

the class ScatterChartActivity 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_scatterchart);
    setTitle("ScatterChartActivity");
    tvX = findViewById(R.id.tvXMax);
    tvY = findViewById(R.id.tvYMax);
    seekBarX = findViewById(R.id.seekBar1);
    seekBarX.setOnSeekBarChangeListener(this);
    seekBarY = findViewById(R.id.seekBar2);
    seekBarY.setOnSeekBarChangeListener(this);
    chart = findViewById(R.id.chart1);
    chart.getDescription().setEnabled(false);
    chart.setOnChartValueSelectedListener(this);
    chart.setDrawGridBackground(false);
    chart.setTouchEnabled(true);
    chart.setMaxHighlightDistance(50f);
    // enable scaling and dragging
    chart.setDragEnabled(true);
    chart.setScaleEnabled(true);
    chart.setMaxVisibleValueCount(200);
    chart.setPinchZoom(true);
    seekBarX.setProgress(45);
    seekBarY.setProgress(100);
    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setTypeface(tfLight);
    l.setXOffset(5f);
    YAxis yl = chart.getAxisLeft();
    yl.setTypeface(tfLight);
    // this replaces setStartAtZero(true)
    yl.setAxisMinimum(0f);
    chart.getAxisRight().setEnabled(false);
    XAxis xl = chart.getXAxis();
    xl.setTypeface(tfLight);
    xl.setDrawGridLines(false);
}
Also used : Legend(com.github.mikephil.charting.components.Legend) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 53 with YAxis

use of com.github.mikephil.charting.components.YAxis in project MPAndroidChart by PhilJay.

the class StackedBarActivity 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("StackedBarActivity");
    tvX = findViewById(R.id.tvXMax);
    tvY = findViewById(R.id.tvYMax);
    seekBarX = findViewById(R.id.seekBar1);
    seekBarX.setOnSeekBarChangeListener(this);
    seekBarY = findViewById(R.id.seekBar2);
    seekBarY.setOnSeekBarChangeListener(this);
    chart = findViewById(R.id.chart1);
    chart.setOnChartValueSelectedListener(this);
    chart.getDescription().setEnabled(false);
    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    chart.setMaxVisibleValueCount(40);
    // scaling can now only be done on x- and y-axis separately
    chart.setPinchZoom(false);
    chart.setDrawGridBackground(false);
    chart.setDrawBarShadow(false);
    chart.setDrawValueAboveBar(false);
    chart.setHighlightFullBarEnabled(false);
    // change the position of the y-labels
    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setValueFormatter(new MyAxisValueFormatter());
    // this replaces setStartAtZero(true)
    leftAxis.setAxisMinimum(0f);
    chart.getAxisRight().setEnabled(false);
    XAxis xLabels = chart.getXAxis();
    xLabels.setPosition(XAxisPosition.TOP);
    // chart.setDrawXLabels(false);
    // chart.setDrawYLabels(false);
    // setting data
    seekBarX.setProgress(12);
    seekBarY.setProgress(100);
    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);
// chart.setDrawLegend(false);
}
Also used : Legend(com.github.mikephil.charting.components.Legend) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis) MyAxisValueFormatter(com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter)

Example 54 with YAxis

use of com.github.mikephil.charting.components.YAxis in project MPAndroidChart by PhilJay.

the class AxisRendererTest method testComputeAxisValues.

@Test
public void testComputeAxisValues() {
    YAxis yAxis = new YAxis();
    yAxis.setLabelCount(6);
    AxisRenderer renderer = new YAxisRenderer(null, yAxis, null);
    renderer.computeAxis(0, 100, false);
    float[] entries = yAxis.mEntries;
    assertEquals(6, entries.length);
    // interval 20
    assertEquals(20, entries[1] - entries[0], 0.01);
    assertEquals(0, entries[0], 0.01);
    assertEquals(100, entries[entries.length - 1], 0.01);
    yAxis = new YAxis();
    yAxis.setLabelCount(6);
    yAxis.setGranularity(50f);
    renderer = new YAxisRenderer(null, yAxis, null);
    renderer.computeAxis(0, 100, false);
    entries = yAxis.mEntries;
    assertEquals(3, entries.length);
    // interval 50
    assertEquals(50, entries[1] - entries[0], 0.01);
    assertEquals(0, entries[0], 0.01);
    assertEquals(100, entries[entries.length - 1], 0.01);
    yAxis = new YAxis();
    yAxis.setLabelCount(5, true);
    renderer = new YAxisRenderer(null, yAxis, null);
    renderer.computeAxis(0, 100, false);
    entries = yAxis.mEntries;
    assertEquals(5, entries.length);
    // interval 25
    assertEquals(25, entries[1] - entries[0], 0.01);
    assertEquals(0, entries[0], 0.01);
    assertEquals(100, entries[entries.length - 1], 0.01);
    yAxis = new YAxis();
    yAxis.setLabelCount(5, true);
    renderer = new YAxisRenderer(null, yAxis, null);
    renderer.computeAxis(0, 0.01f, false);
    entries = yAxis.mEntries;
    assertEquals(5, entries.length);
    assertEquals(0.0025, entries[1] - entries[0], 0.0001);
    assertEquals(0, entries[0], 0.0001);
    assertEquals(0.01, entries[entries.length - 1], 0.0001);
    yAxis = new YAxis();
    yAxis.setLabelCount(5, false);
    renderer = new YAxisRenderer(null, yAxis, null);
    renderer.computeAxis(0, 0.01f, false);
    entries = yAxis.mEntries;
    assertEquals(5, entries.length);
    assertEquals(0.0020, entries[1] - entries[0], 0.0001);
    assertEquals(0, entries[0], 0.0001);
    assertEquals(0.0080, entries[entries.length - 1], 0.0001);
    yAxis = new YAxis();
    yAxis.setLabelCount(6);
    renderer = new YAxisRenderer(null, yAxis, null);
    renderer.computeAxis(-50, 50, false);
    entries = yAxis.mEntries;
    assertEquals(5, entries.length);
    assertEquals(-40, entries[0], 0.0001);
    assertEquals(0, entries[2], 0.0001);
    assertEquals(40, entries[entries.length - 1], 0.0001);
    yAxis = new YAxis();
    yAxis.setLabelCount(6);
    renderer = new YAxisRenderer(null, yAxis, null);
    renderer.computeAxis(-50, 100, false);
    entries = yAxis.mEntries;
    assertEquals(5, entries.length);
    assertEquals(-30, entries[0], 0.0001);
    assertEquals(30, entries[2], 0.0001);
    assertEquals(90, entries[entries.length - 1], 0.0001);
}
Also used : YAxisRenderer(com.github.mikephil.charting.renderer.YAxisRenderer) AxisRenderer(com.github.mikephil.charting.renderer.AxisRenderer) YAxisRenderer(com.github.mikephil.charting.renderer.YAxisRenderer) YAxis(com.github.mikephil.charting.components.YAxis) Test(org.junit.Test)

Aggregations

YAxis (com.github.mikephil.charting.components.YAxis)54 XAxis (com.github.mikephil.charting.components.XAxis)48 Legend (com.github.mikephil.charting.components.Legend)22 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)11 AxisBase (com.github.mikephil.charting.components.AxisBase)10 LineData (com.github.mikephil.charting.data.LineData)8 LineDataSet (com.github.mikephil.charting.data.LineDataSet)7 XFormatter (com.a5corp.weather.utils.XFormatter)5 Entry (com.github.mikephil.charting.data.Entry)5 MyMarkerView (com.xxmassdeveloper.mpchartexample.custom.MyMarkerView)5 ArrayList (java.util.ArrayList)5 Typeface (android.graphics.Typeface)4 View (android.view.View)4 OsmandSettings (net.osmand.plus.OsmandSettings)4 SuppressLint (android.annotation.SuppressLint)3 Paint (android.graphics.Paint)3 SpannableString (android.text.SpannableString)3 LimitLine (com.github.mikephil.charting.components.LimitLine)3 MarkerView (com.github.mikephil.charting.components.MarkerView)2 YAxisRenderer (com.github.mikephil.charting.renderer.YAxisRenderer)2