diff --git a/src/com/jjoe64/graphview/BarGraphView.java b/src/com/jjoe64/graphview/BarGraphView.java index 2a3a87c7f..1bb675afa 100644 --- a/src/com/jjoe64/graphview/BarGraphView.java +++ b/src/com/jjoe64/graphview/BarGraphView.java @@ -41,8 +41,9 @@ public BarGraphView(Context context, String title) { @Override public void drawSeries(Canvas canvas, GraphViewDataInterface[] values, float graphwidth, float graphheight, float border, double minX, double minY, double diffX, double diffY, - float horstart, GraphViewSeriesStyle style) { - float colwidth = (graphwidth - (2 * border)) / values.length; + float horstart, GraphViewSeriesStyle style, int serieNum) { + //float colwidth = (graphwidth - (2 * border)) / values.length / seriesCount; + float colwidth = (graphwidth) / values.length / getSeriesCount(); paint.setStrokeWidth(style.thickness); paint.setColor(style.color); @@ -58,7 +59,7 @@ public void drawSeries(Canvas canvas, GraphViewDataInterface[] values, float gra paint.setColor(style.getValueDependentColor().get(values[i])); } - canvas.drawRect((i * colwidth) + horstart, (border - y) + graphheight, ((i * colwidth) + horstart) + (colwidth - 1), graphheight + border - 1, paint); + canvas.drawRect((i * getSeriesCount() * colwidth) + horstart + (colwidth * serieNum), (border - y) + graphheight, ((i * getSeriesCount() * colwidth) + horstart) + (colwidth - 1) + (colwidth * serieNum), graphheight + border - 1, paint); } } } diff --git a/src/com/jjoe64/graphview/GraphView.java b/src/com/jjoe64/graphview/GraphView.java index b0d32d866..5f540b168 100755 --- a/src/com/jjoe64/graphview/GraphView.java +++ b/src/com/jjoe64/graphview/GraphView.java @@ -1,5 +1,5 @@ /** - * This file is part of GraphView. +f * This file is part of GraphView. * * GraphView is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -19,17 +19,22 @@ package com.jjoe64.graphview; +import java.io.File; +import java.io.FileOutputStream; import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; +import java.util.Random; import android.content.Context; +import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.Rect; import android.graphics.RectF; +import android.os.Environment; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; @@ -65,7 +70,7 @@ private class GraphViewContentView extends View { */ public GraphViewContentView(Context context) { super(context); - setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); + setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); } /** @@ -153,7 +158,7 @@ protected void onDraw(Canvas canvas) { paint.setStrokeCap(Paint.Cap.ROUND); for (int i=0; i maxX) { + viewportStart = maxX - viewportSize; + } + + // labels have to be regenerated + if (!staticHorizontalLabels) horlabels = null; + if (!staticVerticalLabels) verlabels = null; + viewVerLabels.invalidate(); + } + graphViewContentView.invalidate(); + } + + public void saveCanvasAsImage(){ + Bitmap bitmap = Bitmap.createBitmap( this.getWidth(), this.getHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + this.draw(canvas); + + String root = Environment.getExternalStorageDirectory().toString(); + File myDir = new File(root + "/measuready_images"); + myDir.mkdirs(); + Random generator = new Random(); + int n = 10000; + n = generator.nextInt(n); + String fname = "Graph-"+ n +".jpg"; + File file = new File (myDir, fname); + if (file.exists ()) file.delete (); + try { + FileOutputStream out = new FileOutputStream(file); + bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); + out.flush(); + out.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/src/com/jjoe64/graphview/LineGraphView.java b/src/com/jjoe64/graphview/LineGraphView.java index 538159415..2e6b2677e 100644 --- a/src/com/jjoe64/graphview/LineGraphView.java +++ b/src/com/jjoe64/graphview/LineGraphView.java @@ -51,7 +51,7 @@ public LineGraphView(Context context, String title) { } @Override - public void drawSeries(Canvas canvas, GraphViewDataInterface[] values, float graphwidth, float graphheight, float border, double minX, double minY, double diffX, double diffY, float horstart, GraphViewSeriesStyle style) { + public void drawSeries(Canvas canvas, GraphViewDataInterface[] values, float graphwidth, float graphheight, float border, double minX, double minY, double diffX, double diffY, float horstart, GraphViewSeriesStyle style, int serieNum) { // draw background double lastEndY = 0; double lastEndX = 0;