Graphs using CGI

Posted on 1998-08-12
Last Modified: 2013-12-25
I want to generate graphs on a HTML page automatically(on the fly) using the data entered through a form in the web.... How do I go about . If I cannot do it is there any other way of doing it (like ASP or something like that)....Please suggest a solution fast as it is a bit urgent.!!!
Question by:studoo
LVL 28

Expert Comment

ID: 1831480
What kind of information will there be in that graph ??
If you want to display bar-diagrams you can use a table with colored cells. As for example are generated by Nedstat counter

see for example

If you want more complicated graphs, then you could use an applet and write the parameters.

This of course is all cgi (including ASP).

If you really want to make images on the fly, I know it is being done, but I don't know what program is used for that. It is probably not so easy, because you have to know a lot about the image-format.


Expert Comment

ID: 1831481
What platform will you be developing on?

Expert Comment

ID: 1831482
If you're using C for your cgi scripts then you can obtain gdlib by Thomas Boutell for free. It's a C based library that allows cgi scripts to create images on the fly. You can obtain it at It's easy to use and very helpful.
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.


Expert Comment

ID: 1831483
There are two basic ways to do this.  Well, one "basic" way and another more complicated method.  

If you need something sophisticated, you probably want to get ahold of the GNU (c-based) graphics library ( which can be used to generate gif and other graphic files on the fly and includes plotting and charting functions.

The more widely used method of generating graphs is to simply reference a static image and "stretch" it by using HEIGHT and WIDTH commands, as in:
<IMG SRC="img/blueblock.gif" ALT="xxx" HEIGHT=15 WIDTH=136 BORDER=1>

In the above example, I have a gif called "blueblock.gif" which is a small 15x1 image, and I stretch the width to match the measurement I want to visualize.  You can use this technique to make horizontal or vertical bar charts.  (see:

If you need something like pie charts, you're going to have to generate a complete .gif file and the GNU Plot/graphics libraries are what you need.

Either one of these methods will work with Unix or NT.

Hope this helps.

Accepted Solution

wisdom042597 earned 50 total points
ID: 1831484
Let me know if the answer above is acceptable.  

LVL 10

Expert Comment

ID: 1831485
Studoo-- Found this on the net... If you like, I will post as answer...
Found it @

<%      Set xl = CreateObject("Excel.Application")
      Set fs = CreateObject("AspChart.clsFileSystem")
      ' Was there a previously created chart?      If Session("szLastChart") <> Empty Then
            fs.DeleteFile Session("szLastChart")      End If
      ' Get the path to create the chart in
      szChartPath = Server.MapPath(Request.ServerVariables("PATH_INFO"))
      ' Strip the name of this file off the path
      For i = Len(szChartPath) To 1 Step -1            If Mid(szChartPath,i,1) = "\" Then
                  Exit For            End If      Next      ' Truncate the full path
      szChartPath =  Left(szChartPath, i)      ' Get a temporary filename
      szFullChartName = fs.GetTempFileName(CStr(szChartPath))
      Session("szLastChart") = szFullChartName      ' Add a new workbook
    xl.workbooks.Add    ' Setup titles
    xl.activeworkbook.Sheets(1).Range("B1:M1").Value = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
    xl.activeworkbook.Sheets(1).Range("A2").Value = "Apples"
    xl.activeworkbook.Sheets(1).Range("A3").Value = "Oranges"
    xl.activeworkbook.Sheets(1).Range("A4").Value = "Kiwis"
   ' Fill with random data    For x = 1 To 12        For y = 1 To 3
            xl.activeworkbook.Sheets(1).Range("A1").Offset(y, x).Value = Rnd() * 100
        Next    Next      ' Select the data
    xl.activeworkbook.Sheets(1).Range("A1:M4").Select      ' Add a chart
    xl.Charts.Add      ' Format the chart
    xl.activechart.SetSourceData xl.Sheets("Sheet1").Range("A1:M4"), 1
    xl.activechart.Location 1    xl.activechart.HasDataTable = True
    xl.activechart.DataTable.ShowLegendKey = True      ' Export the chart
    xl.activechart.export szFullChartName, "GIF"    
    xl.activeworkbook.Close False
      ' Get just the filename since the chart is already local
      ' relative to this script      For i = Len(szFullChartname) To 1 Step -1
            If Mid(szFullChartname,i,1) = "\" Then                  Exit For            End If      Next
      ' Truncate the full path
      szChartName =  Right(szFullChartname, Len(szFullChartName)-i)
      ' Write out a tag to show the chart
      Response.Write "<IMG SRC=""" + szChartName + """>"      Set xl = Nothing
      Set fs = Nothing%>

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Changing Audit Policies through scripting 5 69
Bartender label printing - switch on and off graphics 3 54
OS Selection Menu 1 46
Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question