for (int j = 0; j < buffer.size(); j += 4) {
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[j + 2]))
continue;
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[j]))
break;
//设置柱状图的颜色为渐变色
LinearGradient linearGradient = new LinearGradient(0, 0, 0, 2000,Color.GREEN, Color.WHITE, Shader.TileMode.CLAMP);
mRenderPaint.setShader(linearGradient);//目标Paint即为绘制柱的Paint
c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],
buffer.buffer[j + 3], mRenderPaint);
if (drawBorder) {
c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],
buffer.buffer[j + 3], mBarBorderPaint);
}
}
效果图: