如何绘制带有点但之间没有线的图表引擎时间序列?
how to draw an achartengine TimeSeries with points but no lines between them?
我目前通过将 XYSeriesRenderer 颜色设置为白色来模拟此功能:
final XYSeriesRenderer goodEventSeriesRenderer = new XYSeriesRenderer();
goodEventSeriesRenderer.setColor(Color.WHITE);
goodEventSeriesRenderer.setPointStyle(PointStyle.POINT);
goodEventSeriesRenderer.setShowLegendItem(false);
goodEventSeriesRenderer.setAnnotationsTextSize(textSize + 2);
goodEventSeriesRenderer.setAnnotationsColor(Color.GREEN);
我尝试调用 setLineWidth(0)
,它通常在其他图形系统中工作以缩小线条,但只是返回点之间的细线。
那么,如何获得时间序列图表,其中一些 TimeSeries 在它们的点之间有线,而有些则没有?我 运行 将 achartengine 编译到我的程序中,而不是来自 jar 文件,所以请随时帮助我破解源代码。
以下是 AChartEngine 允许 .setLineWidth(0)
压缩线条的不同之处:
--- a/app/src/main/java/org/achartengine/chart/AbstractChart.java
+++ b/app/src/main/java/org/achartengine/chart/AbstractChart.java
@@ -302,6 +302,7 @@ public abstract class AbstractChart implements Serializable {
Path path = new Path();
int height = canvas.getHeight();
int width = canvas.getWidth();
+ float strokeWidth = paint.getStrokeWidth();
float[] tempDrawPoints;
if (points.size() < 4) {
@@ -310,7 +311,10 @@ public abstract class AbstractChart implements Serializable {
tempDrawPoints = calculateDrawPoints(points.get(0), points.get(1), points.get(2),
points.get(3), height, width);
path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
- path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
+ if (strokeWidth > 0.0f)
+ path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
+ else
+ path.moveTo(tempDrawPoints[2], tempDrawPoints[3]);
int length = points.size();
for (int i = 4; i < length; i += 2) {
@@ -323,7 +327,10 @@ public abstract class AbstractChart implements Serializable {
if (!circular) {
path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
}
- path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
+ if (strokeWidth > 0.0)
+ path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
+ else
+ path.moveTo(tempDrawPoints[2], tempDrawPoints[3]);
}
if (circular) {
path.lineTo(points.get(0), points.get(1));
diff --git a/app/src/main/java/org/achartengine/chart/LineChart.java b/app/src/main/java/org/achartengine/chart/LineChart.java
index 55365e3..be0937b 100644
--- a/app/src/main/java/org/achartengine/chart/LineChart.java
+++ b/app/src/main/java/org/achartengine/chart/LineChart.java
@@ -81,7 +81,8 @@ public class LineChart extends XYChart {
public void drawSeries(Canvas canvas, Paint paint, List<Float> points, XYSeriesRenderer renderer,
float yAxisValue, int seriesIndex, int startIndex) {
float lineWidth = paint.getStrokeWidth();
- paint.setStrokeWidth(renderer.getLineWidth());
+ float lineWidth1 = renderer.getLineWidth();
+ paint.setStrokeWidth(lineWidth1);
final FillOutsideLine[] fillOutsideLine = renderer.getFillOutsideLine();
for (FillOutsideLine fill : fillOutsideLine) {
@@ -227,8 +228,13 @@ public class LineChart extends XYChart {
public void drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y,
int seriesIndex, Paint paint) {
float oldWidth = paint.getStrokeWidth();
- paint.setStrokeWidth(((XYSeriesRenderer) renderer).getLineWidth());
- canvas.drawLine(x, y, x + SHAPE_WIDTH, y, paint);
+ float lineWidth = ((XYSeriesRenderer) renderer).getLineWidth();
+
+ if (lineWidth > 0.0) {
+ paint.setStrokeWidth(lineWidth);
+ canvas.drawLine(x, y, x + SHAPE_WIDTH, y, paint);
+ }
+
paint.setStrokeWidth(oldWidth);
if (isRenderPoints(renderer)) {
pointsChart.drawLegendShape(canvas, renderer, x + 5, y, seriesIndex, paint);
我目前通过将 XYSeriesRenderer 颜色设置为白色来模拟此功能:
final XYSeriesRenderer goodEventSeriesRenderer = new XYSeriesRenderer();
goodEventSeriesRenderer.setColor(Color.WHITE);
goodEventSeriesRenderer.setPointStyle(PointStyle.POINT);
goodEventSeriesRenderer.setShowLegendItem(false);
goodEventSeriesRenderer.setAnnotationsTextSize(textSize + 2);
goodEventSeriesRenderer.setAnnotationsColor(Color.GREEN);
我尝试调用 setLineWidth(0)
,它通常在其他图形系统中工作以缩小线条,但只是返回点之间的细线。
那么,如何获得时间序列图表,其中一些 TimeSeries 在它们的点之间有线,而有些则没有?我 运行 将 achartengine 编译到我的程序中,而不是来自 jar 文件,所以请随时帮助我破解源代码。
以下是 AChartEngine 允许 .setLineWidth(0)
压缩线条的不同之处:
--- a/app/src/main/java/org/achartengine/chart/AbstractChart.java
+++ b/app/src/main/java/org/achartengine/chart/AbstractChart.java
@@ -302,6 +302,7 @@ public abstract class AbstractChart implements Serializable {
Path path = new Path();
int height = canvas.getHeight();
int width = canvas.getWidth();
+ float strokeWidth = paint.getStrokeWidth();
float[] tempDrawPoints;
if (points.size() < 4) {
@@ -310,7 +311,10 @@ public abstract class AbstractChart implements Serializable {
tempDrawPoints = calculateDrawPoints(points.get(0), points.get(1), points.get(2),
points.get(3), height, width);
path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
- path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
+ if (strokeWidth > 0.0f)
+ path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
+ else
+ path.moveTo(tempDrawPoints[2], tempDrawPoints[3]);
int length = points.size();
for (int i = 4; i < length; i += 2) {
@@ -323,7 +327,10 @@ public abstract class AbstractChart implements Serializable {
if (!circular) {
path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
}
- path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
+ if (strokeWidth > 0.0)
+ path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
+ else
+ path.moveTo(tempDrawPoints[2], tempDrawPoints[3]);
}
if (circular) {
path.lineTo(points.get(0), points.get(1));
diff --git a/app/src/main/java/org/achartengine/chart/LineChart.java b/app/src/main/java/org/achartengine/chart/LineChart.java
index 55365e3..be0937b 100644
--- a/app/src/main/java/org/achartengine/chart/LineChart.java
+++ b/app/src/main/java/org/achartengine/chart/LineChart.java
@@ -81,7 +81,8 @@ public class LineChart extends XYChart {
public void drawSeries(Canvas canvas, Paint paint, List<Float> points, XYSeriesRenderer renderer,
float yAxisValue, int seriesIndex, int startIndex) {
float lineWidth = paint.getStrokeWidth();
- paint.setStrokeWidth(renderer.getLineWidth());
+ float lineWidth1 = renderer.getLineWidth();
+ paint.setStrokeWidth(lineWidth1);
final FillOutsideLine[] fillOutsideLine = renderer.getFillOutsideLine();
for (FillOutsideLine fill : fillOutsideLine) {
@@ -227,8 +228,13 @@ public class LineChart extends XYChart {
public void drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y,
int seriesIndex, Paint paint) {
float oldWidth = paint.getStrokeWidth();
- paint.setStrokeWidth(((XYSeriesRenderer) renderer).getLineWidth());
- canvas.drawLine(x, y, x + SHAPE_WIDTH, y, paint);
+ float lineWidth = ((XYSeriesRenderer) renderer).getLineWidth();
+
+ if (lineWidth > 0.0) {
+ paint.setStrokeWidth(lineWidth);
+ canvas.drawLine(x, y, x + SHAPE_WIDTH, y, paint);
+ }
+
paint.setStrokeWidth(oldWidth);
if (isRenderPoints(renderer)) {
pointsChart.drawLegendShape(canvas, renderer, x + 5, y, seriesIndex, paint);