Join 3,552 readers in helping fund MetaFilter (Hide)


How do I get an automatically generated line graph from a text file with a list of numbers?
June 25, 2007 8:44 AM   Subscribe

Is there a program that can automatically create line graphs from a text file with a list of numbers?

Is there a program that I can have running in the background of my windows machine that will take a text file with a list of numbers, formatted as follows...

121
324
53546
4343
2342
etc...

and produce a line graph in jpeg, jpg, bmp, or any other common picture format?
posted by kaozity to Computers & Internet (15 answers total) 2 users marked this as a favorite
 
There are several libraries that can do this, but they all require a hint of programming. Are you familiar with any programming languages?
posted by AaRdVarK at 8:47 AM on June 25, 2007


gnuplot?

website here. It's command line but very configurable. Can do png output.
posted by handee at 8:51 AM on June 25, 2007


I am most comfortable in c++ and and getting used to php. If need be, learning a new language is not an issue.
posted by kaozity at 8:57 AM on June 25, 2007


Kaozity: ROOT might be just up your alley then. You can get it at root.cern.ch and it is used for data analysis. I've written programs in ROOT/C++ to do just what you are asking, and it wasn't difficult at all. Took maybe a day, and I'm not that familiar with C++.
posted by Loto at 9:02 AM on June 25, 2007


For windows, Graph is simple and effective.

(Caveat: AFAIK, it won't run "in the background". You put your data in, it produces a graph, end of story. I'm not sure why you want something which will run in the background, maybe if you explain more about what you're doing you'll get better answers.)
posted by anaelith at 9:05 AM on June 25, 2007


Well, I have data that is changing every minute. So i would want the program to go in every couple of minutes or so and automatically update the graph that it is producing.
posted by kaozity at 9:55 AM on June 25, 2007


LabView can take data in and graph it, but I'm not so sure about the exporting, or how pretty it would be. It's been some time.
posted by Comrade_robot at 10:01 AM on June 25, 2007


It sounds like you are going to need to roll your own solution. With the ROOT framework, and using C++, it isn't hard to create a program that will read from a file every X minutes and update a graph. The graph can be exported, too, pretty easily. I'm working on data acquisition software right now and am involved in a very similar project, except analysis is done as an event occurs rather than reading in from a file.

Another option would be to use Cygwin and use cron and some shell tools to do this for you, which may or may not be easier depending on your experience with Linux and shell scripting.
posted by Loto at 10:10 AM on June 25, 2007


I'd definitely say just go with gnuplot and a shell script.
posted by dmd at 10:36 AM on June 25, 2007


For something really simple in C, I recommend gdchart. I use the Python interface for simple graphs. For complicated graphs I use Python's matplotlib.

Surprisingly, there is no really simple way to do this. I have about 3/4 of the code written to provide this as a service over the web, something like Joe Gregorio's Sparklines. But I have never had the sustained interest to finish it.
posted by Nelson at 10:45 AM on June 25, 2007


rrdtool will make you the plots, and take care of aggregating over time and so forth. But it makes some assumptions about time-regularity of your datapoints.

gnuplot is a good option too.

If you're comfortable "programming", perl with the various libraries built around GD.pm can do a lot with only minimal effort.

If you're on a PC, think about just loading it in Excel, though I wouldn't wish the automation part on anyone I liked.


rrdtool is probably your best best for little/no programming. Perl with GD or python with SciLab/matplotlib are probably the best if you want to do a little coding.
posted by freebird at 10:53 AM on June 25, 2007


kaozity: Well, I have data that is changing every minute. So i would want the program to go in every couple of minutes or so and automatically update the graph that it is producing.
Oooh- THE program you need is logparser, which is a MS-created free utility that's since been included in the resource kit.

Why you need logparser:
  1. It's native to windows/MS-produced
  2. It comes as a self-contained command line exe suitable for batch or scheduled tasks- no install required- or as a COM .dll that you can register for use in scripts of all types- so if your [favorite script language] in Windows supports using COM objects, you can just use the logparser object in your preferred scripting format
  3. It can output to any number of formats from any number of inputs- and obviously this includes CSV -> line chart .jpg
  4. It has an internal T-SQL like engine to allow for some fairly complex and/or nested data computations
  5. It supports "tailing" or checkpointing a file, so that it can rebuild a graph as the file grows automatically- which would be perfect if you want it to just stay running, and constantly updating your .jpg image as new data is appended to the text/.csv file
  6. Once you become familiar with it, you'll find that it can solve a lot of common problems as it can natively and seamlessly support input formats as diverse as STDIN, file systems, perf logs, registry, active directory, event logs, etc, and output formats that are similar (SQL, XML, CSV, graph, etc)
A simple example:
logparser.exe -i:CSV "SELECT * INTO myOutput.jpg FROM myfile.txt" -headerRow:off -o
:CHART -charttype:Line -groupsize:800x600

posted by hincandenza at 11:33 AM on June 25, 2007


I find that pychart + python is very simple and powerful. Output is easy in SVG or PDF. PNG output needs ghostscript installed.

Assuming that your x axis is increasing by 1 for each value you listed above, the matching code is:

from pychart import *

data = [
(0, 121),
(1, 324),
(2, 53546),
(3, 4343),
(4, 2342),
]

# if the data is in a file, try
# data = [(i, int(line)) for i, line in enumerate(open("\\data.txt"))]

l = line_plot.T(data=data, label="misc")
ar = area.T(x_axis=axis.X(label="time"), y_axis=axis.Y(label="value"))
ar.add_plot(l)
c = canvas.init('t.svg')
ar.draw(c)
c.close()
posted by bonecrusher at 12:55 PM on June 25, 2007


You might be able to use RRDtool. I'd at least poke at the site to see if it does what you want.
posted by blacklite at 4:22 PM on June 25, 2007


It'd be relatively easy to use R to do this sort of thing as well. http://www.r-project.org/
posted by chrisamiller at 4:51 PM on June 25, 2007


« Older TouchpanelFilter: Is it possib...   |  Can I make my tap water better... Newer »
This thread is closed to new comments.