如何在LineChart中绘制单元格
我能够动态显示线条,但找不到如何绘制内部单元格。
我遵循了这些示例
https://github.com/PhilJay/MPAndroidChart/issues/3751
MPAndroidChart- How to add cells inside grids like Graph sheet?
答案 0 :(得分:0)
尝试这种方式
在layout.xml文件中
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
在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));
答案 1 :(得分:0)
您可以覆盖AxisRenderer.drawGridLine并更改网格线的宽度。
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))