demand
Below, the left side of the table, text, copy information in the right display manner in FIG.
Modify the code as follows
文件HorizontalBarChartRenderer.java中
@Override
public void drawValues(Canvas c) {
// if values are drawn
if (isDrawingValuesAllowed(mChart)) {
...
for (int i = 0; i < mChart.getBarData().getDataSetCount(); i++) {
...
// if only single values are drawn (sum)
if (!dataSet.isStacked()) {
...
// if each value of a potential stack should be drawn
} else {
...
while (index < dataSet.getEntryCount() * mAnimator.getPhaseX()) {
...
if (vals == null) {
...
} else {
...
for (int k = 0; k < transformed.length; k += 2) {
...
if (dataSet.isDrawValuesEnabled()) {
drawValue(c, formattedValue, x, y + halfTextHeight, color);
}
//新增如下代码
//起始或者结束值为0
if(formattedValue.trim().equals("0")){
float textWidth = Utils.calcTextWidth(mValuePaint, "happy2020");
//如果为开始值为负数,则往左侧显示文本
if(vals[0]<0||vals[1]<0){
//写标题
drawValue(c,"happy2020",x-textWidth-30, y, Color.RED);
//反之,右侧显示文本
}else {
drawValue(c,"happy2020",x+30, y,
Color.RED);
}
}
...
}
}
...
}
}
MPPointF.recycleInstance(iconsOffset);
}
}
}