gpt4 book ai didi

android - 使用 AndroidPlot 在图形上自定义点

转载 作者:太空宇宙 更新时间:2023-11-03 12:40:01 25 4
gpt4 key购买 nike

任何使用过 AndroidPlot 库的人都可以告诉我如何在图表上绘制自定义点。到目前为止,我正在使用 LineAndPointRenderer 类并将线条设置为透明。我想至少更改点的大小,但如果可能的话,可以使用自定义图像。

P.S 拥有 1500 个代表的人需要创建一个“AndroidPlot”标签。

最佳答案

通过创建我自己的渲染器解决了这个问题。

import android.graphics.*;

import com.androidplot.series.XYSeries;
import com.androidplot.exception.PlotRenderException;
import com.androidplot.util.ValPixConverter;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.XYPlot;
import com.androidplot.xy.XYSeriesRenderer;


public class CustomPointRenderer<FormatterType extends LineAndPointFormatter> extends XYSeriesRenderer<FormatterType> {

private float circleWidth = 1;

public CustomPointRenderer(XYPlot plot) {
super(plot);
}

@Override
public void onRender(Canvas canvas, RectF plotArea) throws PlotRenderException {
for(XYSeries series : getPlot().getSeriesListForRenderer(this.getClass())) {
drawSeries(canvas, plotArea, series, getFormatter(series));
}
}
@Override
protected void doDrawLegendIcon(Canvas canvas, RectF rect, FormatterType formatter) {
// horizontal icon:
float centerY = rect.centerY();
float centerX = rect.centerX();

if(formatter.getFillPaint() != null) {
canvas.drawRect(rect, formatter.getFillPaint());
}
if(formatter.getLinePaint() != null) {
canvas.drawLine(rect.left, rect.bottom, rect.right, rect.top, formatter.getLinePaint());
}

if(formatter.getVertexPaint() != null) {
canvas.drawPoint(centerX, centerY, formatter.getVertexPaint());
}
}

private void drawSeries(Canvas canvas, RectF plotArea, XYSeries series, LineAndPointFormatter formatter) throws PlotRenderException {
PointF p = null;
XYPlot plot = getPlot();
int size = series.size();

for (int i = 0; i < size; i++) {
Number y = series.getY(i);
Number x = series.getX(i);

if (y != null && x != null) {
p = ValPixConverter.valToPix(x, y, plotArea,
plot.getCalculatedMinX(),
plot.getCalculatedMaxX(),
plot.getCalculatedMinY(),
plot.getCalculatedMaxY());

if (formatter.getVertexPaint() != null) {
boolean offScreen = p.x > plotArea.right || p.y > plotArea.bottom || p.x < plotArea.left || p.y < plotArea.top;
if(!offScreen)
canvas.drawCircle(p.x, p.y - circleWidth, circleWidth, formatter.getVertexPaint());
}
}
}
}

public void setWidth(float width){
circleWidth = width;
}
}

关于android - 使用 AndroidPlot 在图形上自定义点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10169080/

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