jjoe64 / graphview Goto Github PK
View Code? Open in Web Editor NEWAndroid Graph Library for creating zoomable and scrollable line and bar graphs.
Home Page: https://github.com/jjoe64/GraphView/wiki
License: Other
Android Graph Library for creating zoomable and scrollable line and bar graphs.
Home Page: https://github.com/jjoe64/GraphView/wiki
License: Other
If a LineGraph has more than approximately 150 values, setting drawBackground=true has no effect
I can't quote in my layout. And it cause "android.view.InflateException: Binary XML file line #6: Error inflating class android.jar.com.jjoe64.graphview.BarGraphView". How can i solve it?
I'm trying to get graph with big width (~1500 px) to put em then in horizontal scroll view, and what I see that y-bar width is become so huge that graph become ugly and deformed.
It will be cool also have possibility to disable x,y bars (not only labels, but also space reserved for them).
When adding 2 or more series in realtime, only 1 value will be shown in Bar or Line Graph View.
Hi,
are you sure that line 81-88 in GraphView create the vertical lines and 90-103 the horizontal lines? Seems to be other way round...
Therefore the methods which load the labels and the variables horlabels and verlabels are swapped.
there is a method graphView.setBackgroundColor();
but no graphView.setTextColor(Color.BLACK) so there are no labels if the background is white.
instead of representing data of the form (1, 3) (2.8) (3.43), I want to paint the form data (21/12/12, 3), (22/12/12, 8) (12/23/12, 43). I tried to use the date format of milliseconds elapsed since 1970, but when I zoom or when I change the viewport does not work well. Any suggestions or an example? Thank you very much. greetings
Hi
The library is useful but it only works if hardware acceleration is turned off (on 4.0+). However that also makes it quite slow for what we are trying to do.
Is it possible for you to add hardware acceleration support so it works when GPU acceleration is turned on?
Best regards,
PA
I had a problem in Android 4 it wasn't smooth scaling. It would only update the screen once I lift my fingers.
A quick fix was in GraphView.java.
Comment out "scaleDetector.isInProgress()" like so:
if (scalable && scaleDetector != null) {
scaleDetector.onTouchEvent(event);
handled = false;//scaleDetector.isInProgress();
}
It now scales and zooms at the same time but that's only a plus for me :)
Hello. I have some issues with BarGraphView; (vertical lines count and barwidth)
There are quick fixes:
//BarGraphView.java
//float colwidth = (graphwidth - (2 * border)) / values.length;
float colwidth = graphwidth / values.length;
//GraphView.java
// horizontal labels + lines
int hors = horlabels.length;
for (int i = 0; i <= horlabels.length; i++) {
paint.setColor(Color.DKGRAY);
float x = ((graphwidth / hors) * i) + horstart;
canvas.drawLine(x, height - border, x, border, paint);
paint.setTextAlign(Align.CENTER);
if (i < horlabels.length) {
paint.setColor(Color.WHITE);
canvas.drawText(horlabels[i], x + (graphwidth / hors) / 2, height - 4, paint);
}
}
Hi, first of all thanks for the great library!
Am having a problem when scrolling over a series that has a subserie that has Y=0 values. When all the values visible on the viewport are Y=0 line disapears. Scrolling back/forward (where Y > 0) line gets drawn again. Haven't been able to fix it myself :/
Maybe this is releted to #29
Thanks for the help!
Is there any chance to make the charts more.... soft? The lines are heavily pixelated, and it just looks..... cheap :S
If they were more high-res, or antialiased - that would make this library the bomb! :)
The graph does not show labels
if you zoom out too wide, the graph jumps from the left to the right corner and vise versa. And sometimes to graph isn't visible anymore...
Like the topic states, when piching to zoom is released, viewport moves a bit to the right or left. When dealing with a large set of values, and zoomed in too much, that could be disturbing.
Video of the problem:
https://www.youtube.com/watch?v=OfdQdeiEAU0
A user named @Lauszus posted a possible source of problem since one of commits:
#71 (comment)
I Quote:"I believe I had the same problem with the viewport jumping around after this commit: ba7ed0f, so I'm actually using an older version for my app right now"
Set it via method and not override the GraphView class.
GraphView looks great; the only thing I think may be missing for my use case would be a click handler, e.g. so I can tap a point on a line chart and get a pop-up with more details. I know detecting tap is tricky when you're handling onTouchEvent, but I thought I'd put a request in.
I'll probably try (another o/s android chart lib) first, and if I don't like it I may come back and fork GraphView and try to add the feature.
Thanks!
how to set a explicit viewport height and the user can scroll (vertical) the graph ?
automatically deletes old values
Problem: Y axis labels aren't showing.
What I found:
Using the debugger, I see that in the following code, numLabels = 0 because graphheight/GraphViewConfig.HORIZONTAL_LABEL_HEIGHT
= 71/80, or less than 1. If I hack the library and set GraphViewConfig.HORIZONTAL_LABEL_HEIGHT
(which is set to 80 in the library code) to something smaller than 71, the y-axis labels show.
synchronized private String[] generateVerlabels(float graphheight) {
int numLabels = (int) (graphheight/GraphViewConfig.HORIZONTAL_LABEL_HEIGHT);
String[] labels = new String[numLabels+1];
double min = getMinY();
double max = getMaxY();
if (max == min) {
// if min/max is the same, fake it so that we can render a line
max = max*1.05d;
min = min*0.95d;
}
for (int i=0; i<=numLabels; i++) {
labels[numLabels-i] = formatLabel(min + ((max-min)*i/numLabels), false);
}
return labels;
}
So that the developer could use it like that:
// x value as string
new GraphViewData("monday", 44), new GraphViewData("tuesday", 32), new GraphViewData("wednesday", 44)
// or y value as string
new GraphViewData(44, "monday"), new GraphViewData(32, "tuesday"), new GraphViewData(44, "wednesday")
Label color
Grid color
Background color
==> should be possible to define a hook for value-depending colors
Hi,
like I wrote you on google+ was the graphview not updating when adding data in realtime.
The android version used was 4.1.1 on a Samsung Galaxy S3 LTE.
I tested it now with the emulator on the versions 2.3.3 (API 10), 4.0.3 (API 15) and 4.2 (API 17): On this APIs is the graph updated like expected.
Only when running a emulater with API 16 (4.1.2) or the phone (4.1.1) is the graph not drawn.
The strange thing is, that it is updating the labels on the y axis (but not on the x), and thereby not drawing the graph. It updates the graph as soon as one clicks on it.
Attached are pictures that show the graph before (output) and after clicking (expected output).
Hi,
First of all: Thank's for this useful code!
I have issues with LineGraphView when all the y values are the same, like this:
iSerie = new GraphViewData[] {
new GraphViewData(1, 1400000)
, new GraphViewData(2, 1400000)
, new GraphViewData(3, 1400000)
, new GraphViewData(4, 1400000) };
In this case: no line are showed :(
public class MyBarGraphView extends GraphView {
public MyBarGraphView(Context context, String title) {
super(context, title);
}
@Override
public void drawSeries(Canvas canvas, GraphViewData[] values, float graphwidth, float graphheight,
float border, double minX, double minY, double diffX, double diffY,
float horstart) {
float colwidth = (graphwidth - (2 * border)) / values.length;
// draw data
for (int i = 0; i < values.length; i++) {
float valY = (float) (values[i].valueY - minY);
float ratY = (float) (valY / diffY);
float y = graphheight * ratY;
canvas.drawRect((i * colwidth) + horstart, (border - y) + graphheight, ((i * colwidth) + horstart) + (colwidth - 1), graphheight + border - 1, paint);
int tmpColor = paint.getColor();
// -----Set values on top of graph---------
paint.setTextAlign(Align.LEFT);
paint.setColor(Color.rgb(255, 255, 255));
float margin = -4;
if (y+12>=graphheight) margin=12;
canvas.drawText(String.valueOf(values[i].valueY), (i * colwidth) + horstart+3, (border - y) + graphheight+margin, paint);
paint.setColor(tmpColor);
}
}
}
Here I am outputing values of bars with white color. "margin" is variable for cases when bar fills all bar height - than I need to output text inside of a bar, not on the top.
The android version used was 4.1.1 on a Samsung Galaxy S3 LTE.
I tested it now with the emulator on the versions 2.3.3 (API 10), 4.0.3 (API 15) and 4.2 (API 17): On this APIs is the graph updated like expected.
Only when running a emulater with API 16 (4.1.2) or the phone (4.1.1) is the graph not drawn.
The strange thing is, that it is updating the labels on the y axis (but not on the x), and thereby not drawing the graph. It updates the graph as soon as one clicks on it.
The height of row doesn't get expanded as the text size changed, which cause overlapping problem.
Hi
If no data series' are added and the graph view has a setViewPort when you try scroll the GraphView causes a Force Close.
Thanks for the great library!
I can handle the empty check myself, but it might be a good case to check for.
The error happens on this line in GraphView
highest = values[values.length-1].valueX;
Stack trace:
java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1
E/AndroidRuntime(31521): at com.jjoe64.graphview.GraphView.getMaxX(GraphView.java:469)
E/AndroidRuntime(31521): at com.jjoe64.graphview.GraphView$GraphViewContentView.onDraw(GraphView.java:67)
E/AndroidRuntime(31521): at android.view.View.draw(View.java:13458)
E/AndroidRuntime(31521): at android.view.View.draw(View.java:13342)
E/AndroidRuntime(31521): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
E/AndroidRuntime(31521): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
E/AndroidRuntime(31521): at android.view.View.draw(View.java:13340)
E/AndroidRuntime(31521): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
E/AndroidRuntime(31521): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
E/AndroidRuntime(31521): at android.view.View.draw(View.java:13340)
E/AndroidRuntime(31521): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
E/AndroidRuntime(31521): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
E/AndroidRuntime(31521): at android.view.View.draw(View.java:13340)
E/AndroidRuntime(31521): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
E/AndroidRuntime(31521): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
E/AndroidRuntime(31521): at android.view.View.draw(View.java:13340)
E/AndroidRuntime(31521): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
E/AndroidRuntime(31521): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
E/AndroidRuntime(31521): at android.view.View.draw(View.java:13461)
E/AndroidRuntime(31521): at android.widget.FrameLayout.draw(FrameLayout.java:467)
E/AndroidRuntime(31521): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2183)
E/AndroidRuntime(31521): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2256)
E/AndroidRuntime(31521): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2151)
E/AndroidRuntime(31521): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2019)
E/AndroidRuntime(31521): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1830)
E/AndroidRuntime(31521): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
E/AndroidRuntime(31521): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
E/AndroidRuntime(31521): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
E/AndroidRuntime(31521): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
E/AndroidRuntime(31521): at android.view.Choreographer.doFrame(Choreographer.java:525)
E/AndroidRuntime(31521): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
E/AndroidRuntime(31521): at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime(31521): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(31521): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(31521): at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime(31521): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(31521): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(31521): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime(31521): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime(31521): at dalvik.system.NativeStart.main(Native Method)
Hi!
Great library, really easy to use and very nice code!
I wanted to fix min and max Y, but manual method was not good enough. In my case, I wanted maxY to be at least 20, but more if the values are higher than that. Overriding getMaxY() fixed a problem for me, but I had to change function modifier from private
to protected
.
Any chance you could change that in core?
Hi,
i have this problem with the graphview library:
http://stackoverflow.com/questions/18533120/android-graphview-shows-wrong-graphs-with-setnumverticallabels
If i change the y-axis values in the demo, the graph is not displayed correct!
Goal is to use GraphView from xml without the need for java code.
Styles etc.
Code from https://github.com/Kusand/GraphView
add public void setTextSize(float value) to GraphView to then use as
paint.setTextSize(textSize);
then client projects can use
res/values/dimensions.xml
14spgetResources().getDimension(R.dimen.ChartTextSize)
I've a problem about Bar in BarChartGraph. I push a 33-elements array but char are smaller of the entire graph, in the graph remain a no used space.
I attached an image.
This is the XML code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtX"
android:text="X: 0"
android:textSize="15sp"></TextView>
<TextView
android:id="@+id/txtZ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="39dp"
android:text="Z: 0"
android:textSize="15sp" />
[....]
<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="39dp"
android:ems="10"
android:inputType="textMultiLine"
android:focusable="false">
</EditText>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:id="@+id/graph1" />
</LinearLayout>
And this the code about graph in the main class:
GraphViewData[] data;
GraphView graphView;
// Inizializzazioni utili per il grafico
data = new GraphViewData[(N/2)+1]; // N=64
graphView = new BarGraphView(this, "example") { //Prova a mettere primad di questo setHorizontalabe
@Override
protected String formatLabel(double value, boolean isValueX) {
if (isValueX) {
return Double.toString(value);
} else return super.formatLabel(value, isValueX); // let the y-value be normal-formatted
}
};
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);
for (int i=0; i<(N/2)+1; i++)
data[i] = new GraphViewData(i, new_sig[i]);
graphView.setBackgroundColor(Color.BLACK);
graphView.addSeries(new GraphViewSeries(data));
graphView.invalidate();
graphView.redrawAll();
Thank's a lot for your support!
This adds a few lins to the GraphView.java onDraw method to make sure the view doesn't through an exception when being rendered in the layout editor.
MinX/MaxX not refreshed?
http://stackoverflow.com/questions/13822765/android-graphview-axis-problems/13874153#13874153
Hello, I did not find any method to remove all series, kind of to reset the chart, so I wrote one. It is trivial, but very useful:
public void removeAllSeries()
{
for (int i = 0; i < graphSeries.size(); i++)
graphSeries.remove(i);
}
in GraphView.java
It would be great, if the "drawBackground" could be set in the GraphViewStyle, so we could use it per series.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.