gpt4 book ai didi

java - MPandroidChart)如何应用两种颜色来setFillColor

转载 作者:行者123 更新时间:2023-12-01 19:55:45 25 4
gpt4 key购买 nike

example

我已经尝试过了。请帮助我..我真的不知道。我认为这与 Canvas 类有关。

自定义线图渲染器

我觉得颜色不是根据x值填充的,而是一次性填充的。

这很难,因为我不习惯 Canvas 。请帮助我。

以下是绘制线条和填充颜色的三种方法。

   @Override
protected void drawLinearFill(Canvas c, ILineDataSet dataSet, Transformer trans, XBounds bounds) {
final Path filled = mGenerateFilledPathBuffer;

final int startingIndex = bounds.min;
final int endingIndex = bounds.range + bounds.min;
final int indexInterval = 128;

int currentStartIndex = 0;
int currentEndIndex = indexInterval;
int iterations = 0;

// Doing this iteratively in order to avoid OutOfMemory errors that can happen on large bounds sets.
do {

currentStartIndex = startingIndex + (iterations * indexInterval);
currentEndIndex = currentStartIndex + indexInterval;
currentEndIndex = currentEndIndex > endingIndex ? endingIndex : currentEndIndex;

if (currentStartIndex <= currentEndIndex) {
generateFilledPath(dataSet, currentStartIndex, currentEndIndex, filled);

trans.pathValueToPixel(filled);

final Drawable drawable = dataSet.getFillDrawable();
if (drawable != null) {

drawFilledPath(c, filled, drawable);
} else {
//////Here part of applying color
drawFilledPath(c, filled, dataSet.getFillColor(), dataSet.getFillAlpha());
}
}

iterations++;

} while (currentStartIndex <= currentEndIndex);
}

@Override
protected void drawFilledPath(Canvas c, Path filledPath, int fillColor, int fillAlpha) {

int color = (fillAlpha << 24) | (fillColor & 0xffffff);

if (clipPathSupported()) {
Log.e("clipPathSupported","1");
int save = c.save();

c.clipPath(filledPath);

c.drawColor(color);
c.restoreToCount(save);
} else {
Log.e("clipPathSupported","2");
// save
Paint.Style previous = mRenderPaint.getStyle();
int previousColor = mRenderPaint.getColor();

// set
mRenderPaint.setStyle(Paint.Style.FILL);
mRenderPaint.setColor(color);

c.drawPath(filledPath, mRenderPaint);

// restore
mRenderPaint.setColor(previousColor);
mRenderPaint.setStyle(previous);
}
}

private void generateFilledPath(final ILineDataSet dataSet, final int startIndex, final int endIndex, final Path outputPath) {


final float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart);
final float phaseY = mAnimator.getPhaseY();
final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED;

final Path filled = outputPath;
filled.reset();

final Entry entry = dataSet.getEntryForIndex(startIndex);

filled.moveTo(entry.getX(), fillMin);
filled.lineTo(entry.getX(), entry.getY() * phaseY);

// create a new path
Entry currentEntry = null;
Entry previousEntry = entry;
for (int x = startIndex + 1; x <= endIndex; x++) {

currentEntry = dataSet.getEntryForIndex(x);

if (isDrawSteppedEnabled) {
filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY);
}

filled.lineTo(currentEntry.getX(), currentEntry.getY() * phaseY);

previousEntry = currentEntry;
}

// close up
if (currentEntry != null) {
filled.lineTo(currentEntry.getX(), fillMin);
}

filled.close();
}

最佳答案

您可以使用着色器,相同:

 mRenderPaint.shader = LinearGradient(fromX, fromY, toX, toY, color1,
color2,
Shader.TileMode.CLAMP)

关于java - MPandroidChart)如何应用两种颜色来setFillColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59043428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com