我使用组合图表绘制叠加的条形图和顶部的折线图。 当我将条形阴影设置为true时,会隐藏一些条形图。 这是我将bar shadow设置为true的代码。
public void setupChart(CombinedChart combinedChart)
{
combinedChart.setDrawOrder(new CombinedChart.DrawOrder[]{CombinedChart.DrawOrder.BAR, CombinedChart.DrawOrder.LINE});
combinedChart.setNoDataText("");
combinedChart.setNoDataTextDescription("");
combinedChart.setDescription(null);
combinedChart.setDrawGridBackground(false);
combinedChart.setDrawBarShadow(true);
combinedChart.setBackgroundColor(getResources().getColor(R.color.transparent));
XAxisValueFormatter customX=new MyXAxisValueFormatter();
XAxis xAxis=combinedChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawAxisLine(false);
xAxis.setDrawLabels(true);
xAxis.setDrawGridLines(false);
xAxis.setGridColor(getResources().getColor(R.color.Gray));
xAxis.setValueFormatter(customX);
xAxis.setSpaceBetweenLabels(2);
YAxisValueFormatter customY=new MyYAxisValueFormatter();
YAxis leftAxis=combinedChart.getAxisLeft();
leftAxis.setLabelCount(4, false);
leftAxis.setDrawAxisLine(false);
leftAxis.setDrawGridLines(false);
leftAxis.setValueFormatter(customY);
leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setSpaceTop(15f);
YAxis rightAxis=combinedChart.getAxisRight();
rightAxis.setEnabled(false);
combinedChart.getLegend().setEnabled(false);
}
我得到以下图表
条形阴影设置为false的相同代码
combinedChart.setDrawBarShadow(false);
生成如下图表,条形图符合预期。
我在这里做了什么故障吗?
如果这是我不希望的错误,我可以使用网格线来实现条形阴影吗?
不过很棒的图书馆。
答案 0 :(得分:0)
感谢菲尔。我通过GitHub得到了回复。我想这个修复程序应该在下一个版本中出来。但这是需要在BarChartRenderer类中更新的方法。
它基本上在绘制实际条形图之前绘制阴影
protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) {
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
mShadowPaint.setColor(dataSet.getBarShadowColor());
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
// initialize the buffer
BarBuffer buffer = mBarBuffers[index];
buffer.setPhases(phaseX, phaseY);
buffer.setBarSpace(dataSet.getBarSpace());
buffer.setDataSet(index);
buffer.setInverted(mChart.isInverted(dataSet.getAxisDependency()));
buffer.feed(dataSet);
trans.pointValuesToPixel(buffer.buffer);
// draw the bar shadow before the values
if (mChart.isDrawBarShadowEnabled()) {
for (int j = 0; j < buffer.size(); j += 4) {
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[j + 2]))
continue;
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[j]))
break;
c.drawRect(buffer.buffer[j], mViewPortHandler.contentTop(),
buffer.buffer[j + 2],
mViewPortHandler.contentBottom(), mShadowPaint);
}
}
// if multiple colors
if (dataSet.getColors().size() > 1) {
for (int j = 0; j < buffer.size(); j += 4) {
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[j + 2]))
continue;
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[j]))
break;
// Set the color for the currently drawn value. If the index
// is
// out of bounds, reuse colors.
mRenderPaint.setColor(dataSet.getColor(j / 4));
c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],
buffer.buffer[j + 3], mRenderPaint);
}
} else {
mRenderPaint.setColor(dataSet.getColor());
for (int j = 0; j < buffer.size(); j += 4) {
if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[j + 2]))
continue;
if (!mViewPortHandler.isInBoundsRight(buffer.buffer[j]))
break;
c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],
buffer.buffer[j + 3], mRenderPaint);
}
}
}
希望这有帮助。