3
는 다음과 같이 라인에 "붙어 있습니다.AndroidPlot 사용자 정의 관절
또는, 적어도이 (라인과 같은 색의 바깥 쪽 원)처럼 보이게하는 방법에 대해 설명합니다.
어떤 도움 ?
는 다음과 같이 라인에 "붙어 있습니다.AndroidPlot 사용자 정의 관절
또는, 적어도이 (라인과 같은 색의 바깥 쪽 원)처럼 보이게하는 방법에 대해 설명합니다.
어떤 도움 ?
저는 아래쪽 이미지가 사용자 정의 LineAndPointRenderer를 사용한다고 생각합니다.이 또한 사용자가 맨 위에있는 이미지를 재현하는 데 사용해야 할 것입니다.
다음은이 작업을 수행하는 방법에 대한 빠르고 간단한 예입니다. 먼저 새로운 형식의 값이 필요 보유 할 사용자 정의 포맷터를 만들 :
/**
* A LineAndPointFormatter with the addition of paint to be used to "stroke" vertices.
*/
class MyLineAndPointFormatter extends LineAndPointFormatter{
private Paint strokePaint;
/**
* Some quick and dirty hard-coded params
*/
public MyLineAndPointFormatter() {
super(Color.RED, Color.RED, null, null);
strokePaint = new Paint();
strokePaint.setColor(Color.BLACK);
strokePaint.setStrokeWidth(PixelUtils.dpToPix(2));
strokePaint.setStyle(Paint.Style.STROKE);
strokePaint.setAntiAlias(true);
}
public Paint getStrokePaint() {
return strokePaint;
}
@Override
public Class<? extends SeriesRenderer> getRendererClass() {
return MyLineAndPointRenderer.class;
}
@Override
public SeriesRenderer getRendererInstance(XYPlot plot) {
return new MyLineAndPointRenderer(plot);
}
}
다음, 사용자 정의 렌더러 :
/**
* A LineAndPointRenderer that can stroke vertices.
*/
class MyLineAndPointRenderer extends LineAndPointRenderer<MyLineAndPointFormatter> {
public MyLineAndPointRenderer(XYPlot plot) {
super(plot);
}
/**
* Overridden draw method to get the "vertex stroke" effect. 99% of this is copy/pasted from
* the super class' implementation.
* @param canvas
* @param plotArea
* @param series
* @param formatter
*/
@Override
protected void drawSeries(Canvas canvas, RectF plotArea, XYSeries series, LineAndPointFormatter formatter) {
PointF thisPoint;
PointF lastPoint = null;
PointF firstPoint = null;
Paint linePaint = formatter.getLinePaint();
Path path = null;
ArrayList<Pair<PointF, Integer>> points = new ArrayList<Pair<PointF, Integer>>(series.size());
for (int i = 0; i < series.size(); i++) {
Number y = series.getY(i);
Number x = series.getX(i);
if (y != null && x != null) {
thisPoint = ValPixConverter.valToPix(
x,
y,
plotArea,
getPlot().getCalculatedMinX(),
getPlot().getCalculatedMaxX(),
getPlot().getCalculatedMinY(),
getPlot().getCalculatedMaxY());
points.add(new Pair<PointF, Integer>(thisPoint, i));
} else {
thisPoint = null;
}
if(linePaint != null && thisPoint != null) {
// record the first point of the new Path
if(firstPoint == null) {
path = new Path();
firstPoint = thisPoint;
// create our first point at the bottom/x position so filling
// will look good
path.moveTo(firstPoint.x, firstPoint.y);
}
if(lastPoint != null) {
appendToPath(path, thisPoint, lastPoint);
}
lastPoint = thisPoint;
} else {
if(lastPoint != null) {
renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter);
}
firstPoint = null;
lastPoint = null;
}
}
if(linePaint != null && firstPoint != null) {
renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter);
}
Paint vertexPaint = formatter.getVertexPaint();
Paint strokePaint = ((MyLineAndPointFormatter)formatter).getStrokePaint();
PointLabelFormatter plf = formatter.getPointLabelFormatter();
if (vertexPaint != null || plf != null) {
for (Pair<PointF, Integer> p : points) {
PointLabeler pointLabeler = formatter.getPointLabeler();
// if vertexPaint is available, draw vertex:
if(vertexPaint != null) {
canvas.drawPoint(p.first.x, p.first.y, vertexPaint);
}
// if stroke is available, draw stroke:
if(strokePaint != null) {
// you'll probably want to make the radius a configurable parameter
// instead of hard-coded like it is here.
canvas.drawCircle(p.first.x, p.first.y, 4, strokePaint);
}
// if textPaint and pointLabeler are available, draw point's text label:
if(plf != null && pointLabeler != null) {
canvas.drawText(pointLabeler.getLabel(series, p.second), p.first.x + plf.hOffset, p.first.y + plf.vOffset, plf.getTextPaint());
}
}
}
}
}
그리고 마지막으로, 당신의 활동에 새로운 조각 사용 :
MyLineAndPointFormatter format = new MyLineAndPointFormatter();
plot.addSeries(series, format);
을
다음은 SimpleXYPlot 예와 함께 사용했을 때의 모습입니다.
라인을 두껍게하고 더 좋은 배경색을 고르는 것이 더 좋을 수도 있지만 아이디어를 얻을 수 있습니다.
아주 잘 작동합니다. 정확히 내가 필요로하는 것. 고맙습니다. – Zkart