aChartEngine remove lines between points

390 views Asked by At

Is it posible to delete the lines between the points??

Here it is my code:

public Intent execute(Context context) {

String[] titles = new String[] { "Systolic Pressure", "Diastolic Pressure"};


List<double[]> x = new ArrayList<double[]>();
for (int i = 0; i < titles.length; i++) {
  x.add(new double[] { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60 });
}


List<double[]> values = new ArrayList<double[]>();
values.add(new double[] { 108, 110.5, 110, 115, 114, 118, 116, 119, 120, 125.3, 122.2, 123.9 });
values.add(new double[] { 75, 77, 80, 79, 82, 84, 83, 80, 86, 88, 85, 80 });

int[] colors = new int[] { Color.BLUE, Color.RED};
PointStyle[] styles = new PointStyle[] {PointStyle.TRIANGLE, PointStyle.TRIANGLE};
XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
setChartSettings(renderer, " ", " ", " ", 0, 60, 0, 250,Color.WHITE,Color.WHITE); 
renderer.setXLabels(12);
renderer.setYLabels(10);
renderer.setShowGridY(true);
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setZoomButtonsVisible(true);
renderer.setPanLimits(new double[] { 0,60, 0, 250 });
renderer.setZoomLimits(new double[] { 0, 60, 0, 250});
XYMultipleSeriesDataset dataset = buildDataset(titles, x, values);
Intent intent = ChartFactory.getLineChartIntent(context, dataset, renderer,"Anesthesia Sheet");

return intent;   }

and here iti is the graphical result:

enter image description here

2

There are 2 answers

1
PaulT On BEST ANSWER

Rather than using a line chart, use a scatter chart.

Change:

Intent intent = ChartFactory.getLineChartIntent(context, dataset, renderer,"Anesthesia Sheet");

To:

Intent intent = ChartFactory.getScatterChartIntent(context, dataset, renderer,"Anesthesia Sheet");

I tried switching the line charts in my app to scatter charts and it worked as expected - the points were plotted with no connecting lines.

0
Phlip On

I edited Renderer.setLineWidth(0) to respect 0 width lines. The diff thereof looks a little bit like this:

+++ 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();^M

     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)^M
+      path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);^M
+    else^M
+      path.moveTo(tempDrawPoints[2], tempDrawPoints[3]);^M

     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)^M
+        path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);^M
+      else^M
+        path.moveTo(tempDrawPoints[2], tempDrawPoints[3]);^M
+++ 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();^M
+    paint.setStrokeWidth(lineWidth1);^M
     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();^M
+^M
+    if (lineWidth > 0.0) {^M
+      paint.setStrokeWidth(lineWidth);^M
+      canvas.drawLine(x, y, x + SHAPE_WIDTH, y, paint);^M
+    }^M
+^M