Labels

GraphView Library

365 comments:

  1. This is really nice .. but how do we do a 'realtime' graph that updates as soon as values are fed it?

    ReplyDelete
  2. realtime graphs are not implemented "in-house", yet. But with a little hacking you can customize the library within a few minutes to do this. Just add a method to reset the series data and setup a timer.

    I think I will implement a realtime updating feature with an example in the next few weeks.

    ReplyDelete
  3. I'll work on it and if I get something running I'll send it to you .. I'd also like to add a few other graph types (sparklines). Fortunately you've written things in a nice way that will make this relatively pleasurable work, so I'll get on with it .. ;)

    ReplyDelete
  4. One other thing the class needs: support for non-multitouch zoom. There are non-multitouch phones out there, after all...

    ReplyDelete
  5. I want to show 80 bars (each labeled from 1 to 80) and i have a little problem
    is there a way to make the horizontal labels be only in integer format ... for example show 1.. 80 instead of showing some values as 10.70 ...
    when i try the
    String labels[] = new String [80];
    for (int n=0 ; n < 80 ; n++){
    labels[n] = Integer.toString(n+1);
    }
    graphView.setHorizontalLabels(labels);

    they appear to close to one another and also the graph cannot be Scrollable/setScalable

    ReplyDelete
  6. @Άγγελος Παναγιωτάκης
    yes it is possible. you can use custom label formatter.

    ReplyDelete
  7. Nice update Joe! One thing .. did you want to add the ability to do realtime updates in this version as well? If so you need to add removeSeries:

    public boolean removeSeries(GraphViewSeries series) {
    boolean result;
    result = false;
    if (graphSeries.contains(series)) {
    graphSeries.remove(series);
    result = true;
    }
    return result;
    }


    .. this way, in the outer views' OnDraw(), the series can be removed and then replaced with new data, providing a 'realtime update' of the GraphView ..

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  8. By the way, wanted to add that we're using GraphView (with my realtime mods) in the Spantec Fall Detector application, in case you're interested:

    https://market.android.com/details?id=at.spantec.securemotion.falldetector

    It will get an update this week that adds a few more features, and we'll probably try to integrate the new version of GraphView too ..



    (ALSO: the gallery popup on this blog makes commenting really a bore..)

    ReplyDelete
  9. Hi,

    stupid question, but how to reset graph for realtime graph.

    i try many things like:
    layout.invalidate();
    layout.destroyDrawingCache();
    graphView.invalidate();
    graphView.removeSeries(loadServera);
    ...

    but no luck, i'm just start to developing in java for androd :(

    @ibisum how u manage live graph? thanks.

    ReplyDelete
  10. @AmonRa_HR
    you have to invalidate() the GraphViewContentView

    ReplyDelete
    Replies
    1. Jones91 - your help has been immense, thanks so much for being responsive.

      I am new to Android and was wondering how you invalidate() the GraphViewContentView?? Thanks for the assistance.

      Delete
  11. How i can set y-axis with 4 point ?
    thanks you

    ReplyDelete
  12. When we scroll the custom labels are not retained . Its regenerating from '0'. How to retain the custom label during scroll. Kindly suggest . Thanks!!!

    ReplyDelete
  13. @Rathika
    yes, custom labels will be overridden when you scroll or scale. For that, you have to use the custom label formatter (see a example above)

    ReplyDelete
  14. Hi,
    Do you have any updates planned? When placing multiple plots on the same axis is there any way to give them their own y axis labels and scaling? What i mean is if i have one for 0 to 10 and another from 0 to 100 i need them to both fill the whole view and then the y axis have a label of 10 and 100 (maybe in different colors). Can you think of any mods that would make this possible?

    Thanks

    ReplyDelete
  15. Hey, is it possible to implement a functionality to enable the user to touch a point in graph, and gives us the ability to give them more details about the graph as a toast.. e.g. the user touches a point in the graph. and the graph looks up the database, and toasts the date.. Thanks

    ReplyDelete
  16. Hi Mohit,
    it is possible.
    Add the function below to GraphView.java:
    public double[] getViewPort() {
    double vp[] = {viewportStart, viewportSize};
    return vp;
    }

    Then in your activity add:

    //intercepts touch events on the graphview
    @Override
    public boolean dispatchTouchEvent(MotionEvent event)
    {
    switch (event.getAction())
    {
    //when you touch the screen
    case MotionEvent.ACTION_DOWN:

    float x = event.getX(event.getActionIndex()); //the location of the touch on the graphview
    double[] vp = graphView.getViewPort(); //the boundries of what you are viewing from the function you just added
    int width = graphView.getWidth(); //the width of the graphview
    double xValue = vp[0]+ (x/width)*vp[1]; //the x-Value of the graph where you touched

    //add a method to lookup a value and do anything you want based on xValue. You can also implement this for yValue

    break;
    }
    return super.dispatchTouchEvent(event);
    }

    I haven't tested this but it is general idea of how it can be done. I use a similar technique in my app.

    ReplyDelete
    Replies
    1. It's working. But what if I have 2 GraphViews on the layout? How to write touch event for separate graph?

      Thanks.

      Delete
    2. Its not totally correct, touching 0 on the graph isn't 0. However touching the right left of the screen it is 0.

      Delete
  17. Hello,
    The scalability function is not working for me on Android simulator.
    Is anybody able to implement scalability?

    Adi

    ReplyDelete
  18. @Adi
    scaling is not possible on AVD (simulator) because it's not possible to make a two-fingers touch scale gesture. On a real device it will work.

    ReplyDelete
  19. Hello,

    Nice job, thanks !
    I actually work on a bargraph with dynamic time legend. In your example you use 'dateTimeFormatter', wich object is it ? I've tried 'SimpleDateFormatter' but I get a nullPointerExecption ^^
    In your demo folder, is there any file which implements this ?

    bece

    P.S. : Sorry, my english isn't my native language ...

    ReplyDelete
  20. Hi, That's ok, it is a SimpleDateFormatter and I have my time legend. Now I try to display my time legend on two lines :)

    bece

    ReplyDelete
  21. Hello,

    I was wondering if someone can email me or list some steps on how to get the GraphViewDemos project up and running in Eclipse 3.7.1 on Mac OS X 10.6.8. I'm trying to port one of my apps on Apple's App Store to the Android market. This library looks very promising. I haven't touched java in a while but I'm not afraid to re-learn some things. I'm a complete noob when it comes to Eclipse though. So far, Eclipse makes me want to physically remove an important, reproductive member of my body and carelessly toss it into the air..

    When I Import-->Existing Projects into Workspace, Eclipse tries to auto build but is throwing an error, "Project 'GraphViewDemos' is missing required Java project: 'GraphView'". I've already googled and attempted several solutions to the error but haven't gotten any closer to figuring it out.

    If anyone can help, that'd be great. I enjoy having my member and would hate to have to see it go. I also noticed that the project is set up for Android 2.3.3. Would I be able to build, compile, and run this an Android 2.2 AVD?

    Thanks,
    Jason
    7rashcan@gmail.com

    ReplyDelete
  22. Hello again,

    I found the un-intuitive solution to my previous problem. It goes something like this, Import GraphView, then Import GraphViewDemos, then delete GraphView, then Import GraphView again.. Awesome..

    It successfully opens an Android 2.3.3 AVD and launches the demo. My problem now is that whenever I click on any one of the graph examples, the app crashes with a Force Close.

    The first error states that it "Could not find class 'com.jjoe64.graphview.GraphView$GraphViewSeries', referenced from method com.jjoe64.graphviewdemos.SimpleGraph.onCreate". Can anyone tell me what I'm doing wrong?

    Thanks,
    Jason
    7rashcan@gmail.com

    ReplyDelete
    Replies
    1. I also had this really bad experience.

      I was interested by using this library, but I won't go further except if you give me a solution to, at least, run the Example project ...

      Thanks,
      Lionel
      lionelpere [ at ] gmail

      Delete
  23. This comment has been removed by the author.

    ReplyDelete
  24. Hi, your library for drawing graphs is very interesting. You already used it in a project?

    ReplyDelete
  25. @Bas
    many developers are using this library. Originally I developed this library for my Android app "ZAX - Zabbix Monitoring"
    https://market.android.com/details?id=com.inovex.zabbixmobile

    ReplyDelete
  26. Wow this looks great. I am newer to this, and am trying to get the data from a sqlite database. How would i go about doing this?

    ReplyDelete
  27. hello jonas, i have a problem with my label and the graph.. it wont display not until i drag the mobile screen. What will i dot to display the graph and the label even without dragging my screen?

    ReplyDelete
  28. Hello jonas.. what is the use viewport method. When i try to remove viewport method my graph will not move when i tap it. I dont really know what is the exact value to pass inorder to make my graph move from left to right when i tap and also i want to display the current date on the y-axis, right now the display date is not the current date eventhough the date that i format is the current date. thank you very, your help is high appreciated.

    ReplyDelete
  29. I have seen other libraries but I really like yours even though it has no bar chart. I would like to know I can extend the base class to create bar chart class. thanks

    ReplyDelete
  30. Mr.Bibera use graphView.invalidate() to update your labels.

    The viewport method is view portion - ie the section of the graph that is shown. Just set the view port to all of your data to see the whole graph and still be able to move it.

    Mawuli there is a BarGraphView class

    ReplyDelete
  31. Very nice library. The LGPL is a little ambiguous - is it ok to include an unmodified jar in a commericial/paid app?

    Thanks!

    ReplyDelete
  32. @Ian yes
    you have to public the source if you have modified the library.

    ReplyDelete
  33. Hi,

    Can someone send me an example of how using Graphview in Real time.

    thanks

    ReplyDelete
  34. Hi, im using this libary in my bachelor project. I was wondering, if i have set scalable and scrolling to true. The graph becomes jittery because it changes the y axis all the time while im scrolling or zooming, is it possible to lock the y axis to a fixed value?

    Great program btw!!! ;)

    ReplyDelete
  35. Is it possible to use logarithmic scale on the y axis in the AdvancedMultipleSeriesGraph?

    Keep up the good work!

    ReplyDelete
  36. just have a look in the very simple source code and give it a try!

    ReplyDelete
  37. Hi Jonas,

    any news regading real time graph that updates as soon as values are fed it?

    I would appriciate to receive an example from you.

    Thanks again!

    ReplyDelete
  38. @ilan
    sorry I have no time to do this. but it should be really easy to implement. have a look into the source code!

    ReplyDelete
  39. Thanks to every one we had made this library.

    ReplyDelete
  40. Hi I have a same issue that 7rashcan had.
    I imported this demo project and tried to run, but I couldn't. Eclipse said this project has some error.

    "Project 'GraphViewDemos' is missing required Java project: 'GraphView'"

    I thought I had to attach GraphView library on the project. So I did, but still error there.

    How can I try this project? Should I make my own project by following your demo?

    ReplyDelete
  41. Sorry for my stupid question, but where can i change the color of the text along the axes?

    Thanks!

    ReplyDelete
  42. @nina
    you have to hack this in the source code!

    ReplyDelete
  43. @Jonas Gehring
    Oh, I think it will be easier:)

    Thanks for the answer!

    ReplyDelete
  44. well.. there's another project that i was supposed to import to this demo project. this is the reason why nobody's replied to my question lol. thanks Jonas it's working great now.

    ReplyDelete
  45. hey, great libary! for me it would be important to draw a linegraph but also a graph just with dots. is there a chance to draw dotgraph with your libary?

    ReplyDelete
  46. @Anna
    please have a look into the source code! it is really easy to understand and hack it!

    ReplyDelete
  47. Real time weather graph.
    It's receiving temperature from sensor each second.
    http://www.youtube.com/watch?v=ZwH8gD6jgtA

    Please, give me advice. How to create time line from horizontal labels?
    I rewrited you generateHorlabels function.
    It's creating 10 labels with interval 2 minutes.
    But after some time they going out from the left edge and new one are not creating..

    private String[] generateHorlabels(float graphwidth) {
    int numLabels = 10;
    String[] labels = new String[numLabels+1];

    int subMinutes = -20;
    for (int i = 0; i < numLabels+1; i++){
    Calendar now = Calendar.getInstance();
    now.add(Calendar.MINUTE, subMinutes);
    subMinutes = subMinutes + 2;
    int hours = now.get(Calendar.HOUR_OF_DAY);
    int minutes = now.get(Calendar.MINUTE);
    String label = new String();
    if (minutes <= 9)
    label = hours + ":" + "0" + minutes;
    else label = hours + ":" + minutes;
    labels[i] = label;
    }

    return labels;
    }

    ReplyDelete
    Replies
    1. @Ok-Alex

      Really nicely done. Can you share the code on how you got the real time updates to work. Even just basic information on redrawing the graph would be very helpful.

      Thanks!

      Delete
  48. hey, thats great! is there a chance to draw functions like f(x)=x^2?

    ReplyDelete
  49. @soulf
    of course you can do any algorithm! you just have to generate the values...

    ReplyDelete
  50. Hello again,

    I found the un-intuitive solution to my previous problem. It goes something like this, Import GraphView, then Import GraphViewDemos, then delete GraphView, then Import GraphView again.. Awesome..

    It successfully opens an Android 2.3.3 AVD and launches the demo. My problem now is that whenever I click on any one of the graph examples, the app crashes with a Force Close.

    The first error states that it "Could not find class 'com.jjoe64.graphview.GraphView$GraphViewSeries', referenced from method com.jjoe64.graphviewdemos.SimpleGraph.onCreate". Can anyone tell me what I'm doing wrong?

    ReplyDelete
  51. Hi,
    Thanks for the library. I have two quick questions.

    - Is there a way (method) to just add a description for the X, and Y axis? [as to explain what the data in them is? ex. 0,1,2,3...x=Time, 0,1,2,..y=Distance) Or is that something I should change in the code? (which class should I look in? )

    - How can I increment the number of division lines that show in the background of the plots? (in portrait I'm getting something like #, and landscape looks good something like ### )

    Thank you for your help,

    -Cristian

    ReplyDelete
  52. Hi, thanks for great library.
    Is it possible to add margin to the y axis? So the graph Min/Max values not being the top and bottom.

    Thanks for your help :)

    ReplyDelete
  53. Hi,thanks for a helpful library....

    Here we are redrawing the graph after each touch event.

    Can we just create a full graph initially and pan through it?

    ReplyDelete
  54. Hi, first of all a really nice implementation. But I have following problem. I'd like to link the values of the dataset to the values(lables) of the x- y- axis. For example the values for the x-axis are set from 1-34 and the y-axis from 1-18. The given data set is (1,6),(2,3),(3,9). The result is following (1,6) >> x=1,y=12; (2,3) >> x=17, y=6; (3,9) >> x=34 , y=18. The wanted reult would be (1,6) >> x=1,y=6; (2,3) >> x=2, y=3; (3,9) >> x=3 , y=9. The problem is that the values from the data sets will expanded to the max values of the axis. Is there any chance to get it work.
    Every hint is highly appreciated.

    ReplyDelete
  55. Hi John

    I not 100% sure what you are asking but i wanted to do a similar thing (I think, i wanted fixed axis). In GraphView.java the getMaxY() and getMinY() methods return the values that are used for drawing the axis. Modify these methods to get the values used for the max and mins of the axis.

    Hope this helps you a bit

    ReplyDelete
  56. @Boozel,
    thanks a lot for your hint. That was the missing link. I reviewed the GraphView class and found an existing function for the y-axis (setManualYAxisBounds) and based on that I created a similar one for the x-axis and now everything is working
    Cheers John.

    ReplyDelete
  57. Hello.

    Great library!
    But how to integrate a diagram into a fragment?

    Greets Henrik

    ReplyDelete
  58. How do I import this one in the library?Do I need to import it as a jar file?

    ReplyDelete
  59. hello jonas, I've problem with your library here..

    I was adding the jar file to my project but, when I tried to run my project and debug it I found an error that said "not found source", why this happen?

    is it because I was wrong to import the jar file to my project or what? please someone give me hint. thanks.

    ReplyDelete
  60. @c4c0
    when you want to debug the library you need the sources. The jar doesn't include them. If you need this you should import the whole GraphView Project instead of the exported jar file.
    here is a description: http://www.jjoe64.com/2011/07/chart-and-graph-library-for-android.html

    ReplyDelete
  61. Hi Jonas.
    Really really a great library.

    I added library as jar file. I want to change colors of rectangular bars. Also I want to remove the horizontal and vertical lines in the background of the graph. How can I do this?

    Please guide.
    Thanks

    ReplyDelete
    Replies
    1. @Ruchi
      for those customizing for have to use the sources and modify it for your own.

      Delete
  62. Hi!
    Graphs are cool, but I have a problem in this code and I can't find it:

    loaddata.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    String s="1256845851473592438651682465265256262456826841256296842684428716";
    int size = s.length();
    GraphViewData[] cords = new GraphViewData[size/8];
    String data="", seged="";
    double y;
    for(int i=0;i<size/8;i++){
    seged=s.substring(7, size-1);
    data = s.substring(0,7);
    y = Double.valueOf(data);
    s=seged;
    cords[i] = new GraphViewData(i,y);
    }
    graph.addSeries(new GraphViewSeries(cords));
    //graph.setScalable(true);
    //graph.setScrollable(true);
    graph.setVisibility(View.VISIBLE);
    }
    });
    any idea? Thanks!

    ReplyDelete
  63. How exactly do i remove a series from the chart? I want to run it in real time.

    ReplyDelete
  64. I have he same question than davidfla90, how do I remove a series from the chart? something like

    graphView.removeSeries(randomSeries)

    Thanks

    ReplyDelete
    Replies
    1. I have already fixed it:

      Import the GraphView project into your Eclipse workspace, edit the java file src/com.jjoe64.graphview/GraphView.java

      You will found the function

      public void addSeries(GraphViewSeries series) {
      graphSeries.add(series);
      }

      Just add a new function

      public void removeSeries(GraphViewSeries series) {
      graphSeries.remove(series);
      }

      Now, in your current project, if you have the GraphView project correctly linked as a Library you will be able to use the removeSeries just like the addSeries

      Delete
  65. i don't want to use external jar. so how do i draw chart in android?

    ReplyDelete
  66. El ejemplo de la estadistica de barra esta mal. No es
    GraphView graphView = new LineGraphView( es: GraphView graphView = new BarGraphView(
    Malnasiosssss!!!

    ReplyDelete
  67. Any chance that the jar on github will be updated with remove support soon?

    ReplyDelete
  68. Hey !
    Really thanks for this sharing !
    Your lib seems pretty, i wish i'll have fun with it haha
    Nevertheless i have to make some updates for my utility, i'll send you if it works !

    ReplyDelete
  69. I want to do a realtime aplication using this library. Someone can help me?

    For example, in the first step I want to press a button and add a point in the graph.

    ReplyDelete
  70. Is is possible to draw a scatter plot?

    Thanks,
    Jay

    ReplyDelete
  71. Hello. Is it possible to change the color of the labels (textcolor)? As I have a white background, and the text is white :O.


    Regards.
    P.S: Love the Lib! Good Work.

    ReplyDelete
  72. is it possible to change textsize of labels

    ReplyDelete
  73. Have you tested this with Android 4.0? I'm having problems with zooming and scrolling; the scrolling works but is a little erratic and with zooming it only updates if you pinch and then scroll. Also, would it be possible to implement a feature to let you select a point on the graph and show the values at that point?

    ReplyDelete
  74. I want realtime graph !! ;_;

    ReplyDelete
  75. Fantastic library!!!
    A question: in LineGraphView how i can set the number of vertical guidelines? I need to show 5 label on my X-axis! I override formatLabel and then returned
    if (isValueX)
    {
    return label[(int)value];
    }
    where label[] is my string[] of x-axis label; i choose viewport size=4 but i see only label[0], label[2], label[4]... first, last and middle of my viewport size (i see only a vertical guidelines in the middle)!
    How i can set from code the number of vertical guidelines to have same number of label (i need viewport size=4 and all 5 label showed)?
    Thank you :-)

    ReplyDelete
  76. Android 4 is a little buggy.

    ReplyDelete
  77. I made a couple o changes:

    - fixed wrong zoom behaviour on Android 4 (invalidate)
    - fixed wrong zoom behaviour on fast gestures (scalefactor too big)
    - added line thickness as style

    If the author agrees, I'll be glad to post my changes. Just let me know how to proceed.

    Marco.

    ReplyDelete
    Replies
    1. hi marco!
      many thanks for your work.
      The best way is to do a "pull request" on github.

      Delete
    2. Hi Jonas,

      I created an account on github, you should forgive my ignorance but since I'm not familiar with it, I'm unable to find how to pull a request.

      Delete
    3. no go to the project https://github.com/jjoe64/GraphView
      and click on "fork"
      then you checkout your own GraphView-fork (git clone)
      then commit your changes und push it.
      then you can click on "pull request" on github.

      or just send me your changes via mail! g.jjoe64 at googlemail dot com

      Delete
    4. Well, I managed my first GitHub pull request :-)

      Marco

      Delete
    5. Hi Marco, I too have these problems when scrolling. I've checked out the latest version from github, but the problem is still there. Could you please describe the changes you have made or upload your code somewhere?

      Delete
    6. @TheNetStriker:

      Code was put on GitHub for review of the author that, I guess, was not convinced of its "quality".

      Here you can find the modification I proposed to the onScale for the pinch to zoom problem:

      https://github.com/jjoe64/GraphView/pull/10#issuecomment-5807673

      just go to the last snipped presented.

      Best regards,
      Marco

      Delete
  78. Hi,
    I am trying to do a realtime graph. I have added a removeSeries() to the lib, and it works, but how to update the imageView? I wonder addView() is to update the graph, but when I use removeSeries() and addView() in the handler thread, the program crashed. Could you give me some tips? Thank you.

    ReplyDelete
  79. Hi Jonas, I added a couple of features to enable callback on selecting a sample and multi-line labels.
    Have posted a pull request on GitHub for these.

    ReplyDelete
  80. hello jonas,

    I'm vinod new to android development..need one help..
    please say me what to do after downloading the resources which you have mentioned in your blog...please say step by step..
    I just imported the folders separately in eclipse and run it shows force close msg..what i want to do..
    waiting for your reply..

    Regards,
    vinod

    ReplyDelete
    Replies
    1. you just need to download the .jar file.
      copy it to your android project folder.
      in eclipse refresh your project (F5), open the project settings, go to "java build path", tab "libraries", click "Add JARs" and select the downloaded graphview.jar.

      Delete
    2. Great lib, but i have a problem with the JAr.

      I've imported all the neccesary packes (com.jjoe64.graphview.GraphView, com.jjoe64.graphview.GraphView.GraphViewSeries, com.jjoe64.graphview.LineGraphView), but at this example:

      GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
      new GraphViewData(1, 2.0d)
      , new GraphViewData(2, 1.5d)
      , new GraphViewData(3, 2.5d)
      , new GraphViewData(4, 1.0d)
      });

      I got one error: GraphViewData cannot be resolved to a type. What is the problem?

      Thx for your help! :)

      Delete
    3. add
      import com.jjoe64.graphview.GraphView.GraphViewData

      Delete
  81. You sir are what they call Angels! This seems to fit the bill perfectly for my application. Thank you very much for providing all of us with this fantastic utility. Will be sure to credit your work. =P

    One quick question, when was the .jar library last created from the source? Does it include the recent updates that have been made to the code, on GitHub, or is it the last "stable version" if you would like to call it that?

    Thanks very much again!

    ReplyDelete
    Replies
    1. thanks!
      I would use it from the sources (github).
      There are a very patches and it's good for development if you have the sources. Then you could also modify it.

      Delete
    2. OK, I'll do exactly that... (in fact, I already have, haha). Thanks very much for the reply.

      On another note, I've just been reading through a number of your other coding examples and the like, and I must say that it looks incredibly impressive. I'm sure that I'll be back here again soon!

      Delete
  82. Hi,

    Thanks for the awesome library!

    I was trying to do some realtime graph update but I've not been very successful so far.
    I have the code to update the series and after I do a invalidate() to the view but
    doesn't work.
    Is there any example of this available? I searched in the links above but found none.

    Thanks!

    ReplyDelete
    Replies
    1. Working perfectly now, it was some odd bug in ADT caching my resources.

      Delete
    2. Hi Nando.

      Could I ask how you have gone about trying to get the real-time graph update working, because I have made an attempt at it by using invalidate() and then redrawing the graph, but it just does not seem to work? Your help would be greatly appreciated.

      Delete
    3. Sure.

      The workflow is the following.
      I remove the series, then I add them back with updated values and after I call the invalidate() method on the instance I've created for the Graphview.
      The invalidate should be enough as it will signal the system that the view needs to be updated on the next screen update.

      Delete
    4. Hi Nando, I'm trying to implement this in my application, however when I call invalidate() on the instance, the graph doesn't update until I touch to scroll the graph, have you had this problem?

      Delete
    5. Hi Ben,
      Yes I had that problem, initially to see the graph update animation I'd have to keep my finger in the screen. As soon as I'd release, it would stop.

      Again it as all solved when I noticed that I was not calling the invalidate() from the GraphView but rather from the parent view.

      If it helps I can do a example sample with it.

      Delete
  83. Great library!
    I'm trying to take control your source code!
    Thanks

    ReplyDelete
  84. i want that my bar graph should expand or shrink on button event. i have bars in graph, and 3 respective button to each bar..

    please need help, than x in advance

    ReplyDelete
  85. hi.. im working on a project currently which requires graphs on android with dynamic values being loaded into it.. could someone please help me with how to make graphs dynamic? thanks!

    ReplyDelete
    Replies
    1. you have to redraw the Graph everytime your data changes... there's currently no other way.
      You have to hack the graphview code, if you want to restore the zoom/scale state.

      Delete
  86. I have one question. Is this jar is free?? can i use it for any app which is going to release in android market or usable for commercial purpose?

    ReplyDelete
  87. I add some code in the graph view code. But when i am trying to use the method which i added in the graphview.java, it is showing error. How to update the jar file and use that properly??

    ReplyDelete
  88. Learning android and couldnt get the downloaded jar to work.... kept saying NoClassDef error in LogCat.

    To sort this this is what I did.

    1. Created a libs folder in my project folder
    2. copied in the jar to the libs folder
    3. added the external build path into eclipse (BUILD, Add Extrenal Archives..)
    4. Abracadabra.... it now works.

    Dont ask me why... Im a newbie but thought it may help another fellow newbie.

    Now I can play with some graphs and learn a thing or two. Great package jjoe64. Thank you... a donation may well be on its way if I get a android prog published in my lifetime ;~)

    ReplyDelete
  89. I want to use Date/time for the X-as. Anyone here who knows how to use Date objects or something like that for the X-as instead of the double?

    ReplyDelete
  90. after messing around with the graphs for a minute it seems like your onTouchEvent override could use a little tweaking. it would be a good idea to give a little leniency with vertical scroll. notice that when you have those two graphs in a ScrollView (referring to the demo), any movement along the y-axis causes the scroll to be invoked. you should eat a small bit of the y-axis value, because scrolling on any y-delta whatsoever is way too sensitive. furthermore, and relating to the same issue, when the ScrollView (or any other view) eats the touch event after the GraphView attempts to work with it, the GraphView's scroll position is somehow marked incorrectly, and scrolling in the GraphView again jerks the set back to the position it was in before the ScrollView interfered.

    in short, eat some y-axis touch movement for scrolling/scaling. it just seems a little clunky.

    also, it would be nice of GraphView extended from the View class so it can be used directly as a widget like an ImageView or TextView.

    other than that, the api works great. with some tweaking, it could be even better.

    ReplyDelete
  91. I have some single value series' where x doesn't matter and only the y value matters. I want to do it in a bar graph with 3 series', for example....but instead of placing the "Bars" side-by-side, they all overlap one another. How can I get past this? Also, can I change the minimum Y value of the graph?

    ReplyDelete
  92. This comment has been removed by the author.

    ReplyDelete
  93. Is there a way to get the X-as fixed to the graph drawing... So when i scroll the graph the vertical labels will scroll with it.. Any help or tips how to get this would be awesome :D

    ReplyDelete
  94. I mean the horizontal labels.. Any push in the right direction would be awesome.. I just dunno where to start

    ReplyDelete
    Replies
    1. that could be complicated. have a look at the point where the labels where rendered. here you could set a offset for the x-position... good luck

      Delete
    2. Hi Luizje,

      Did you manage to do this?

      If so please share.

      Thanks

      Delete
  95. Hello Jonas Gehring thanks for Awesome Library lately i was trying to modify the code to suit my needs but unfortunately i couldn't get it to work actually i need to set color for horizontal and vertical labels but its not possible it still retains a white color can you give a hint how can i make it work.

    ReplyDelete
    Replies
    1. that's easy.
      have a look into the source GraphView.java line 266 for vertical and line 100 for horizontal labels

      Delete
    2. Hello Jonas! I'm new in Java, so I have a stupid question.. I have changed the lines 266 and 100 in GraphView.java file (WHITE to BLACK) but still no changes in the application.. How is it possible to update/refresh/regenerate the jar file with the new source?

      Here is what I did:
      1. renamed GraphView-2.5.jar to GraphView-2.5.zip
      2. found GraphView.java file and made the required changes
      3. renamed GraphView-2.5.zip to GraphView-2.5.jar
      4. replaced the old jar file in my /lib/ folder to the new one
      5. started Eclipse and launched the application

      the colors of the horizontal and vertical labels are still white..

      Thank You.

      Delete
  96. @ Mr. Jonas Gehring
    Thank you for this extremely useful library. I've recently encountered a problem in implementing your graph. I get the following error during runtime:

    Caused by: java.lang.NoClassDefFoundError: com.jjoe64.graphview.GraphView$GraphViewData[]

    The error is due to the following line:

    GraphViewData[] data = new GraphViewData[count];

    where I've already initialized count

    I've placed the .jar file in my lib folder and added it to my Java Build Path. Anything else I should do?

    It was working fine before. I would appreciate your help. Thank you.

    ReplyDelete
    Replies
    1. Nevermind. Figured it out. After updating the Eclipse Android ADT plugin to version 18, I needed to change the name of the library folder to "libs" from "lib".

      Delete
    2. You saved my sanity, thanks man!

      Delete
  97. Hi

    Could a bar chart be placed horizontally instead of vertically? Also, could labels be placed on top of the bars themselves rather than at the axes?

    Thanks

    ReplyDelete
  98. Great library. Me likey.
    I have a how-to question. How can I set the x-axis labels to reflect only one series. I have two series that represent fuel efficiency over time. One vehicle might be used more and have a series of, say, 5 fill-ups [may1, 5, may3, 6, may5, 5, may9, 6, may11, 6.5] while the second vehicle has only 3 fillups [may4, 7.5, may11, 8.0, may15, 7.2]. Just per chance, my data has the busier vehicle first in my query but the graph sets the X axis to the smaller (second) series (the dates are just examples and the data is non-human readable). I want the entire graph to show all the data, but use the x-axis of the longest series. I hope this question makes sense.

    ReplyDelete
  99. I want plot some graph from databases. There could be some empty points. When data[i]=null or don't initialize data[i] there are errors. I'd like have no conection between lines. Are there any option to do it? (without devided serie into many series)

    ReplyDelete
  100. how to put for example in horizontal label the values 1,2,3,10??
    they have to be scalade, like
    1 2 3 10 20

    is it possible??
    with static label only i can do this
    1 2 3 10 20

    thx

    ReplyDelete
  101. it write bad

    values scalade:
    1--2--3---------------10----------------20
    static labels
    1--2--3--10--20

    ReplyDelete
  102. Hello Jonas
    i'm using your awesome lib GraphView for android but i have a little problem:
    if i make a LineGraphView with opcion
    ((LineGraphView) graphView).setDrawBackground(true);
    it paint the background only if in my GraphViewData[x], x<=146

    why?? can i do something to change it??

    for example


    int n=145;
    GraphViewData[] ciao = new GraphViewData[n+1];
    for (int i=0;i<113;i++)
    ciao[i] = new GraphViewData(i, i);
    for (int i=113;i<=n;i++)
    ciao[i] = new GraphViewData(i, n-i);


    GraphViewSeries exampleSeries = new GraphViewSeries(ciao);

    IT PAINT THE BACKGROUND


    int n=146;
    GraphViewData[] ciao = new GraphViewData[n+1];
    for (int i=0;i<113;i++)
    ciao[i] = new GraphViewData(i, i);
    for (int i=113;i<=n;i++)
    ciao[i] = new GraphViewData(i, n-i);


    GraphViewSeries exampleSeries = new GraphViewSeries(ciao);
    NOT PAINT BACKGROUND

    thank you

    ReplyDelete
  103. Hello !
    I am trying to use the library in order to display a huge amount of points in a line graph. For the moment, I am trying it with 6 GraphViewSeries, containing each 500 points. When I don't scroll, everything is ok. But sometimes, when I scroll, I have a problem. Actually, the values in the x-axes become "reversed". The value on the left of the graph is bigger then the one on the right. As I guess my explanations arent very clear, I have added some screenshots.
    - Here is the screenshot before scrolling, everything is ok : http://imageshack.us/photo/my-images/24/graphok.jpg/
    - Here is the screenshot after scrolling: http://imageshack.us/photo/my-images/710/graphnotok.jpg/ as you can see, the value on the left (251) is smaller then the one on the right (248). Once my graph is in this state, I can't unscroll in order to display my graph on a normal way again.
    Does anyone know how I could resolve this problem ?
    Thanks in advance !
    Sebastian

    ReplyDelete
    Replies
    1. I guess you have to debug GraphView...

      Delete
  104. I wanted to say "the value on the left (251) is BIGGER then the one on the right (248)." sorry :)

    ReplyDelete
  105. Hi,

    I am using this lib for GraphView and I am facing a problem when I have large number of X values then it does not drawline with every points and at the following line: float spaceY = (float) (lastEndY + ((endY-lastEndY)*xi/(numSpace-1)));

    spaceY comes NaN... and it paints the background like Bars..
    Please let me know the solution .

    ReplyDelete
  106. I'm just starting to look at this library, and I think it will work for what I want to do. One question, is it possible and / or what do you think the difficulty level would be on making the line change colors? ie: I want to have a Y of -100 to 100 with 0 in the middle. As the line goes above, turns a darker shade of green. Goes lower, darker red.

    thoughts?

    ReplyDelete
    Replies
    1. I'd say difficult level "average".
      You have to replace the canvas.drawLine() method with a loop to draw every pixel with another paint (color). You also need good math skills to calculate all the points between start-point and end-point.

      Delete
    2. awesome. thanks for the reply. I wonder, for my case, if it might not just be simpler, and honestly, more usable, to simply have a background image for the graph showing the gradient colors, and then a line that is a contrasting color like yellow.

      I assume changing out the background, or at least making it transparent, placing the graph control over an image is possible?

      thx again for the follow up!

      Delete
  107. Wy does the x-axis by the bar charts never end at the end of the graphview?

    ReplyDelete
  108. Te felicito por la biblioteca! genial!
    Lo que pasa es que le veo un problema... si la función no es continua pinta rectas que pasan por los puntos de discontinuidad... por ejemplo en la función tan(x)

    ReplyDelete
  109. realtime graph values someone?

    ReplyDelete
  110. I have managed to get real time working, sort of. For my application I only needed a scrolling type display with about 30 seconds worth of data. After the data has been collected (about 5-10 misn worth), I redraw the graph with the whole data I recorded.

    First of all I create the series as normal with values that are zero. The time (I use this for the graph x value) is then set to 30 seconds before and then I add 1 second to each reading. Ths gives me a graph with a zero line that starts scrolling to the left as I add data on the end. It works great.

    I had to change the series values from final to I could update them by removing the final. Like this

    /**
    * one data set for a graph series
    */
    static public class GraphViewData {
    public double valueX;
    public double valueY;


    Then I simply update the series data and call invalidate on the graph. First I move all the data points to the left.

    for(int Ptr = 1; Ptr < 30; Ptr++)
    {
    pushData[Ptr - 1].valueX = pushData[Ptr].valueX;
    pushData[Ptr - 1].valueY = pushData[Ptr].valueY;
    }

    I then insert the new value at the end.

    pushData[29].valueX = msTime;
    pushData[29].valueY = SensorLoad[0];

    The only thing that does not update for me is the hor and ver labels. This I am still working on to get it working.

    ReplyDelete
  111. Thank you very much! This is the simplest android graphing library and the only working at first try :)

    ReplyDelete
  112. A quick demo of my system running real time update. This is only running on a 600Mhz Samsung based Android device so not too bad.

    http://www.youtube.com/watch?v=RzUO6wWrB3M

    Sorry about the audio, I have not edited it to remove the background noise.

    Dave...

    ReplyDelete
    Replies
    1. I'm doing something similar but can't get the data to refresh when running on my device, only when running on the emulator. I update the data using remove series then add series, then call invalidate on my graphview object.

      Would it be possible to see some sample code of your activity program.

      Delete
    2. Its okay, I resolved my problem by changing the target SDK version.

      Delete
  113. Hello, i tested your dem 6333621 but i get Runtime Error when it executes layout.addView(graphView);

    Thomas

    ReplyDelete
  114. Hi, using the 2.5 binary I cannot use setDrawBackground (method not found) and also the scroll/zoom doesn't work (graph gets messed up and wont respond after first zoom).

    This is on a ICS galaxy nexus.

    Do I need to use a version from git?

    ReplyDelete
  115. @ajm83. Why not download the source code and include this as part of your application development? It may be more up to date that the binary.

    ReplyDelete
  116. Hi Jonas,

    I have the same error that 7rashcan had(I obtained "Force close").
    This is the error : << Could not find class 'com.jjoe64.graphview.GraphView$GraphViewSeries', referenced from method >>
    I'm added the .jar file and the problem persist.

    Please Help

    Thank you.

    Best regards,
    S.K

    ReplyDelete
  117. Hi again,

    I solved the problem, I made this steps :
    Porperties -> Java Build Path -> Order and Export -> I move the GraphView Jar file up. Finally I clean the project.

    Thx for share.

    Best regards,
    S.K

    ReplyDelete
  118. This comment has been removed by the author.

    ReplyDelete
  119. This comment has been removed by the author.

    ReplyDelete
  120. Jonas/Dave,

    Thanks very much for an excellent application.

    Regarding realtime display, I see there are the methods removeSeries() and addSeries() to update the data. Is there a method to update the view once new data has been added?

    I can implement real time display by calling removeView() then addView() every time I change the data, however I'd like a more efficient way to do this.

    Regards,
    Marc

    ReplyDelete
    Replies
    1. I resolved my problem by changing the SDK specification in the manifest file as follows


      to


      Now when I call invalidate, the display refreshes as desired.

      I now need to get the axes to refresh dynamically.

      Thanks again for a great application.

      Delete
    2. I can't see what your manifest changes where (not appearing on Blog). Could you elaborate?
      I'm also to the stage where realtime data is working, but the invalidate call doesn't seem to fire correctly
      Thanks

      Delete
    3. OK, so I answered my own question. I changed the targetSDKVersion attribute from 16 to 13 in the manifest and life got much better. Real time here I come!

      Delete
  121. Thanks for your application!!
    But I have a problem.

    When I have a serieData with all y values equals (1,6) (2,6) (3,6) (4,6) ..., the application doesn't draw!!

    How can I resolve my problem?

    Vere thanks.
    Javi

    ReplyDelete
  122. Hi, thanks for this great charting package. My question is, is it possible to overlay text (up to 150 chars or so) at the line points. Basically a sort of description of what the point is that's plotted?

    ReplyDelete
  123. Is it possible to change size for labels and legend??? If is how?

    ReplyDelete
  124. If the value is constant i can't draw the graph, As I fix it?
    this is my code:
    for(int i=0; i< array.size();i++){
    if(Double.parseDouble(array.get(i))!=0)
    gvd[i]=new GraphViewData(i, Double.parseDouble(array.get(i)));
    }
    GraphViewSeries gvs=new GraphViewSeries(gvd);
    GraphView gv=new LineGraphView(this, "Data");
    gv.addSeries(gvs);
    LinearLayout ly=(LinearLayout) findViewById(R.id.LayoutPropio);

    ReplyDelete
  125. Hello.
    I was wondering when the pie chart will be avaible to use?

    ReplyDelete
  126. Hi Jonas, thanks for this lib. I have a linegraph and bar graph on the same screen, like the sample, with the same information. Is there any way to link the two graphs so that when I scroll or scale one of them it is done automatically on the other?

    ReplyDelete
  127. Jonas the links to the libraries are not working

    https://github.com/jjoe64/GraphView

    ReplyDelete
  128. Great library! Is there a way to find out the coordinates at which the user clicks on the graph? I want to take an action that depends on where the click occurs.

    ReplyDelete
  129. Nice library jonas !! i am giving custom labels to the graph but when i tried to do the pinch zoom to the graph then then labels which i customise not able to retain those labels ...please suggest how to do that retain labels even if i do the pinch zoom?
    thanks in advance!

    ReplyDelete
  130. Great library, as a self taught developer I got it working fairly quickly (never imported a library before). I am have a problem with graphing multiply lines on one grid. When I copy your example to my app I get an error on what is your line 12 and 21 @ the color.rgb(90,250, 00). I get this message when I hold my mouse over the error: The constructor GraphView.GraphViewSeries(String, int, GraphView.GraphViewData[]) is undefined Could you give me some insight into this? I cant seam to find a solution. Thanks again for your work into putting this together.

    ReplyDelete
  131. Great work. Awesome. I have not tried it yet but looks like its the one I have been looking for all over the internet. Lets see how live rendering with GraphView turns out. Bravo!!!

    ReplyDelete
  132. hi JONAS,
    Awesome work.I have tried it and I have a issue in that how to change the label colour because if i use a white background image then the labels vanishes because its colour is white too,so in that case I have to change the label colour but i can't be able to understand that how this can be done.......Please guide me about that as early as possible,Waiting for your response.Thanks

    ReplyDelete
  133. Hi, I am new to Android. My app forces close when I have already imported the jar file and copied the first example ("how to create a simple graph") to have a test run. i saw the log cat and it says service request failed and unable to resolve host and also set authorisation in error state. do i need to do anything else before this jar works? please help... thanks!

    ReplyDelete
  134. Hi, I tried to run the code but the labels and title are not showing. Could you kindly advise?

    ReplyDelete
  135. Great library, really easy to use. Thanks!

    ReplyDelete
  136. Hi. I'm using your library and I try to add horizontal and vertical labels and they don't appear, the title don't appear too.

    this is the code:

    weightGraph = new LineGraphView(WeightGraph.this, getResources().getString(R.string.WeightProgression));

    //weight series are loaded correctly
    weightGraph.addSeries(weightSeries);


    weightGraph.setHorizontalLabels(new String[] {"test","testing","tested"});

    LinearLayout.LayoutParams Lparams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int)(p.y*0.75));
    weightGraph.setLayoutParams(Lparams);

    LinLayout = (LinearLayout) findViewById(R.id.LinLayout);
    LinLayout.addView(weightGraph, 0);

    Do you know why is this happening? What I'm doing wrong?

    ReplyDelete
    Replies
    1. Hi mate,

      I had the problem. In my case I had a white background for my layout and in GraphView.java, color of the labels is set to white in the code.

      paint.setColor(Color.WHITE);

      I felt a bit stupid at the moment but if it can help...

      ++

      Alex

      Delete
  137. sorry if i ask,why app force close when i click any button in GraphViewDemo project? i can run the project, no error after i import into eclipse except i need to remove @Override, but when click button to view the graph, it force close.. also i cannot run GraphView project because eclipse put red exclamation mark on the project, i right click on the project>android tools>fix project properties but it does not fix anything.. what should i do?

    ReplyDelete
    Replies
    1. ok forget it, i re-read comments above and got the idea to remove current jar and add new jar and its working! except the GraphView project it shows many error in ScaleGestureDetector.class i dunno what, somebody can explain why please?

      Delete
  138. This library works great but on 720p devices the zooming on the graphs does not happen with your fingers, it scales the graph after you release your fingers.
    How can I fix this?

    ReplyDelete
    Replies
    1. I have tested it on the Nokia N9 (running nitdroid), Galaxy S, Galaxy S II, Galaxy S III, HTC One X and Sony Xperia S
      It works properly on the Samsung Galaxy S and S II and the Nokia N9

      BTW everything else is brilliant

      Delete
  139. So far I like the library, but as many different post already mentioned, I am missing the real time adding of data. I looked at the code and it should not be to hard (replacing the arrays with list would be probably the fastest solution...), but making so much changes in some other persons code can be confusing after a version change. Will there be soon more development in that direction (as mentioned last year) or are you to busy?

    ReplyDelete
  140. Great library!

    A have a question. How can I set more space for labels from the left, because I have to put numbers like 0.8340. I moved the whole graph to right but even then not all digits are visible.

    ReplyDelete
  141. Hello excellent job with this library, when version 3.0 will be released... because the 2.5 it can not live charts

    ReplyDelete
  142. It is released. Change the 2.5 in DownloadURL to 3.0 ;-) But the charts are not Updated automatically if they Chartdata is updated in the NOT-UI Thread?

    ReplyDelete
    Replies
    1. If you are unable to make the changes in your applicationgraphs visisble do this:
      layout = (LinearLayout) findViewById(R.id.graph1);
      layout.removeAllViews();
      layout.addView(graphViewVelocity);

      Delete
  143. Hi, i used your library for developing the graph part of Trackthisforme for Android ( https://play.google.com/store/apps/details?id=me.trackthisfor.android ) and it's really easy to customize!
    thanks a lot Jonas.

    Francesco

    ReplyDelete
  144. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  145. hi, how can i move the vertical labels(y axis) from the left side of the chart to the rigth sight?

    ReplyDelete
  146. i need to create the x labels as static values 0,5,10,15,20,25 .
    and y axis values as - 10, -9 ... to 9, 10. if i give the graph view data. it has to draw with respect to those x axis and y axis values. i am able to create the x and y axis values. but graph is not drawing correctly with respect to that values. how to resolve this. please reply

    ReplyDelete
    Replies
    1. hi!
      static labels are only text strings and are not bound to the real data.
      GraphView does set the viewport automatically from minX to maxX and minY to maxY.
      If you want to have a fix viewport (from -10 to 10y and from 0-25x) you have to hack it!

      Delete