Search in sources :

Example 1 with YAxisRenderer

use of com.github.mikephil.charting.renderer.YAxisRenderer in project MPAndroidChart by PhilJay.

the class BarLineChartBase method init.

@Override
protected void init() {
    super.init();
    mAxisLeft = new YAxis(AxisDependency.LEFT);
    mAxisRight = new YAxis(AxisDependency.RIGHT);
    mLeftAxisTransformer = new Transformer(mViewPortHandler);
    mRightAxisTransformer = new Transformer(mViewPortHandler);
    mAxisRendererLeft = new YAxisRenderer(mViewPortHandler, mAxisLeft, mLeftAxisTransformer);
    mAxisRendererRight = new YAxisRenderer(mViewPortHandler, mAxisRight, mRightAxisTransformer);
    mXAxisRenderer = new XAxisRenderer(mViewPortHandler, mXAxis, mLeftAxisTransformer);
    setHighlighter(new ChartHighlighter(this));
    mChartTouchListener = new BarLineChartTouchListener(this, mViewPortHandler.getMatrixTouch(), 3f);
    mGridBackgroundPaint = new Paint();
    mGridBackgroundPaint.setStyle(Style.FILL);
    // mGridBackgroundPaint.setColor(Color.WHITE);
    // light
    mGridBackgroundPaint.setColor(Color.rgb(240, 240, 240));
    // grey
    mBorderPaint = new Paint();
    mBorderPaint.setStyle(Style.STROKE);
    mBorderPaint.setColor(Color.BLACK);
    mBorderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
}
Also used : Transformer(com.github.mikephil.charting.utils.Transformer) ChartHighlighter(com.github.mikephil.charting.highlight.ChartHighlighter) YAxisRenderer(com.github.mikephil.charting.renderer.YAxisRenderer) Paint(android.graphics.Paint) XAxisRenderer(com.github.mikephil.charting.renderer.XAxisRenderer) YAxis(com.github.mikephil.charting.components.YAxis) BarLineChartTouchListener(com.github.mikephil.charting.listener.BarLineChartTouchListener)

Example 2 with YAxisRenderer

use of com.github.mikephil.charting.renderer.YAxisRenderer 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)2 YAxisRenderer (com.github.mikephil.charting.renderer.YAxisRenderer)2 Paint (android.graphics.Paint)1 ChartHighlighter (com.github.mikephil.charting.highlight.ChartHighlighter)1 BarLineChartTouchListener (com.github.mikephil.charting.listener.BarLineChartTouchListener)1 AxisRenderer (com.github.mikephil.charting.renderer.AxisRenderer)1 XAxisRenderer (com.github.mikephil.charting.renderer.XAxisRenderer)1 Transformer (com.github.mikephil.charting.utils.Transformer)1 Test (org.junit.Test)1