如何在 MPAndroidChart BarCart 中的条形图周围绘制边框?
How to draw border around a bar in MPAndroidChart BarCart?
我正在使用 MPAndroidChart 绘制条形图。
如何在显示的图表中的每个条形周围绘制边框?
默认情况下这是不可能的。
您将不得不修改库,特别是 BarChartRenderer
class。
只需获取表示要绘制的柱的 RectF
对象,并在原始柱上再次绘制它,同时将 Paint
模式更改为 STROKE
而不是 FILL
。
当然,您还必须更改 Paint
颜色以区分边框和栏。
因此,在严格搜索和检查库开发人员用来演示库功能的演示应用程序之后,我得到了这个。
BarChart barChart = new BarChart();
BarData barData = new BarData(barDataSet);
//set the appropriate properties of object **barData**
//then set the data property of the chart
barChart.setData(barData);
.
.
.
.
//add border to chart bars
for (IBarDataSet set : barChart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
.
.
.
//set up other properties as well
意图
barData.sliceSpace = 2f
和mas造型
eneficioChar.holeRadius = 1f
val set1 = BarDataSet(entries,seriesLabel)
set1.color = Color.YELLOW
set1.barBorderWidth = 1f
set1.barBorderColor=Color.RED
我正在使用 MPAndroidChart 绘制条形图。 如何在显示的图表中的每个条形周围绘制边框?
默认情况下这是不可能的。
您将不得不修改库,特别是 BarChartRenderer
class。
只需获取表示要绘制的柱的 RectF
对象,并在原始柱上再次绘制它,同时将 Paint
模式更改为 STROKE
而不是 FILL
。
当然,您还必须更改 Paint
颜色以区分边框和栏。
因此,在严格搜索和检查库开发人员用来演示库功能的演示应用程序之后,我得到了这个。
BarChart barChart = new BarChart();
BarData barData = new BarData(barDataSet);
//set the appropriate properties of object **barData**
//then set the data property of the chart
barChart.setData(barData);
.
.
.
.
//add border to chart bars
for (IBarDataSet set : barChart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
.
.
.
//set up other properties as well
意图 barData.sliceSpace = 2f 和mas造型 eneficioChar.holeRadius = 1f
val set1 = BarDataSet(entries,seriesLabel)
set1.color = Color.YELLOW
set1.barBorderWidth = 1f
set1.barBorderColor=Color.RED