0

How can I draw cells inside LineChart

I am able to display lines dynamically, but didn't find how to draw inner cells.

I have followed these examples

https://github.com/PhilJay/MPAndroidChart/issues/3751

MPAndroidChart- How to add cells inside grids like Graph sheet?

any suggestion will be appreciated enter image description here

Tufan
  • 2,789
  • 4
  • 34
  • 52

2 Answers2

0

Try this way

in layout.xml file

<com.github.mikephil.charting.charts.LineChart
     android:id="@+id/chart"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"/>

in Activity.java

LineChart lineChart = (LineChart) findViewById(R.id.chart);
.
.
.
  XAxis xAxis = lineChart.getXAxis();
        xAxis.setDrawAxisLine(true);
        xAxis.setDrawGridLines(true)
xAxis.setGridColor(getResources().getColor(R.color.colorAccent));

.
.
.
 YAxis yAxisRight = lineChart.getAxisRight();
        yAxisRight.setDrawAxisLine(true);
        yAxisRight.setDrawGridLines(true);
yAxisRight.setGridColor(getResources().getColor(R.color.colorAccent));
.
.
.
 YAxis yAxisLeft = lineChart.getAxisLeft();
        yAxisLeft.setDrawGridLines(true);
yAxisLeft.setGridColor(getResources().getColor(R.color.colorAccent));
Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
  • Hi @Aniruddh this will draw x and y axis and change its color , i want to draw small rectangle inside x and y axis – Tufan Sep 27 '18 at 10:51
  • yes, setDrawGridLines(true); it will draw grid Lines in both x and y axis, in which color you have specified but if you want to small rectangle then you can set fixed interval between values you are providing to show in graph. – Aniruddh Parihar Sep 27 '18 at 11:01
  • that's the only way is possible in mpChartLib to show the grid Lines. – Aniruddh Parihar Sep 27 '18 at 11:03
  • the grid lines are showing with custom color, the problem is small rectangle inside x and y – Tufan Sep 27 '18 at 11:08
  • if you want small rectangle between x and y Axis then set a fixed small value interval between values in x and y axis. – Aniruddh Parihar Sep 27 '18 at 11:12
0

You can override AxisRenderer.drawGridLine and change grid line width.

private class CustomXAxisRenderer(
    viewPortHandler: ViewPortHandler,
    xAxis: XAxis,
    trans: Transformer
) : XAxisRenderer(viewPortHandler, xAxis, trans) {

    override fun drawGridLine(c: Canvas?, x: Float, y: Float, gridLinePath: Path?) {
        mGridPaint.strokeWidth = (if (x.toInt() % 5 == 0) 2 else 1).toFloat()
        super.drawGridLine(c, x, y, gridLinePath)
    }

}

...

chart.setXAxisRenderer(CustomXAxisRenderer(mViewPortHandler, mXAxis, mLeftAxisTransformer))
Yonfu
  • 19
  • 2