Wednesday, June 5, 2013

Graph, just a simple graph

For RealBasic there are several Plot, Graph or graphing components to draw simple and even very complex graphs. Some of the more capable components are commercial software and indeed are on a professional level. Sometimes however all that is needed is a quick chart to show some trend or series of data in an application.

Also there are free and open source components out there with again varying levels of complexity and capability. Having used some for a while, we ended up making our own version to be very simple in use and to introduce only one class. So there is not the Graph that can include several Plots that can include several Series objects. This class or component is a single Graph object that can plot a line-graph.


All the data are copied to arrays in the Graph object, no additional files or classes are needed.

In the GraphExample project the Graph object is included and of course with all source code readable and editable. It only draws line graphs; adding bar graphs or other plot types is of course possible. The handling of the text sizing could be more elegant and the scale-values could be simpler. But it comes as source code and free to use and extend.

To figure out the current capabilities (range limiting, x-grid only etc...) do have a rummage round the example project and the Graph source.

We may even extend it ourselves.

Good luck :)

2 comments:

  1. Hi! Im Alan...very nice work, i use this component to graph temperature from the serial port, but i have a problem with this, i want to show the range temperature (-55 to 125) in the Y axis, but only i can see the temperature array values in real time in the Y axis, no range fixed value, can you help me? Thanks, and sorry for my bad english

    ReplyDelete
    Replies
    1. Hi There! Glad you found the component useful. This is rather ancient code by now, in Xojo terms of course.
      Would need to dig out my archives, but rather thought there was a method to override the automatic scaling. If you know the range, would suggest you just hard-code a line in the Paint procedure to overwrite the scale values.
      Hope you can adapt and make it work!

      Delete