Draw Line chart

F

Fan Jin

Hi:
I have built up table in MS Access, and there were data stored in that
table. Now I want to output those data from MS Access to draw a Line
chart. I have install the gem "Gruff", "RMagick", and "ImageMagick" for
drawing. Does anybody know how to do this? Please give some idea.

Thanks
-Jin Fan
 
J

Jonas Pfenniger (zimbatm)

Hi,

the simplest is if you can export your columns of datas into CSV
format. Then you can just read it with the 'csv' libary. See
http://ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html for some usage.
Then it's just a matter of opening the CSV, get the values you want
out of it, and feed them to Gruff.

I'm sure it's also possible to connect to the Access database using
ADO under windows, but it's going to be a bit harder I think. If it's
only a tool for you, I would keep the CSV version, otherwise invest
some time in the ADO version once the first-one is working.
 
F

Fan Jin

zimbatm ... wrote in post #973434:
Hi,

the simplest is if you can export your columns of datas into CSV
format. Then you can just read it with the 'csv' libary. See
http://ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html for some usage.
Then it's just a matter of opening the CSV, get the values you want
out of it, and feed them to Gruff.

I'm sure it's also possible to connect to the Access database using
ADO under windows, but it's going to be a bit harder I think. If it's
only a tool for you, I would keep the CSV version, otherwise invest
some time in the ADO version once the first-one is working.


What tools that I need to use to convert data into CSV format, please?
It seems that I need to install some tools to do this.

-Jin Fan
 
R

Ralf Mueller

zimbatm ... wrote in post #973434:

What tools that I need to use to convert data into CSV format, please?
It seems that I need to install some tools to do this.
Not sure, but MSAccess should have a "Save As"" exporter to CSV. MSExcel definitelyhas one.
 
J

Jonas Pfenniger (zimbatm)

[Note: parts of this message were removed to make it a legal post.]

Is it a one-time task, or does it need to be done many times?
 
F

Fan Jin

Mike Stephens wrote in post #973636:
I know I'll get hate mail as soon as I press Submit but don't ignore the
best gem in the Ruby World.

It's most likely already installed on your computer and it's called
Excel, and it's dead easy to create charts. As a matter of
interest it is equally dead easy to script Access (ie Jet) to get the
data out.

See eg
http://rubyonwindows.blogspot.com/2008/06/automating-excel-creating-charts.html

Thanks a lot. But I still have some problems with get the Range from the
table which imported from the MS Access, cos I do not want to set the
range every time with new table imported. Please give me more hints with
how to do this, thanks.
 
M

Mike Stephens

Fan Jin wrote in post #973892:
I still have some problems with get the Range from the
table which imported from the MS Access, cos I do not want to set the
range every time with new table imported. Please give me more hints with
how to do this, thanks.

Excel does have concepts of the currently active range etc without you
necessarily telling it the details but I would be inclined to use Ruby
to read the Access table into an array and then plonk the data into a
range (rather than getting Excel to import it). It's just a simple
assignment. Since you can find the number of rows retrieved, you can
easily get Ruby to calculate the range. I guess that will be easier when
you then get Ruby to request the Chart. Look at the Ruby on Windows blog
to see how to access Access (Jet) - it's only a few lines of code.
 
F

Fan Jin

Mike Stephens wrote in post #973911:
Fan Jin wrote in post #973892:

Excel does have concepts of the currently active range etc without you
necessarily telling it the details but I would be inclined to use Ruby
to read the Access table into an array and then plonk the data into a
range (rather than getting Excel to import it). It's just a simple
assignment. Since you can find the number of rows retrieved, you can
easily get Ruby to calculate the range. I guess that will be easier when
you then get Ruby to request the Chart. Look at the Ruby on Windows blog
to see how to access Access (Jet) - it's only a few lines of code.

Thanks, that's very great! But after the data has been stored in an
Array,which gem can be used to draw a dynamic chart, please?
 
T

timr

You could definitely do it with the ruby-processing gem, which can
watch a script and update the graph live, so any data changes the
graph is automatically updated. But you would have to build up the
chart from scratch as nobody has built a framework for graphing (as
far as I know). I haven't seen any graphing tools in pure ruby, and
most people doing such scientific graphic end up just using python
which has the numpy and scipy modules.

Alternatively you can get your data into CSV format and import that
into R, gnuplot, or excel and graph it easily. My favorite is R with
the ggplot2 module. You can write an R/ggplot script and R to execute
it from ruby using backtics as quotes (`R <myRscript`).

Science/graphing is ruby's achilles heel.

Tim
 
F

Fan Jin

Mike Stephens wrote in post #973911:
Fan Jin wrote in post #973892:

Excel does have concepts of the currently active range etc without you
necessarily telling it the details but I would be inclined to use Ruby
to read the Access table into an array and then plonk the data into a
range (rather than getting Excel to import it). It's just a simple
assignment. Since you can find the number of rows retrieved, you can
easily get Ruby to calculate the range. I guess that will be easier when
you then get Ruby to request the Chart. Look at the Ruby on Windows blog
to see how to access Access (Jet) - it's only a few lines of code.

Hi:
I have successfully read data into arrays a[] and b[], but I do not know
how to plonk the data into range format for drawing chart in excel.
Could you show me more details,please? Thanks.
-Jin Fan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top