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.
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.


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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python 2.7 - French characters 6 59
inactive users 13 71
running netsh advfirewall set rule on multiple computers 3 36
Python variable _ manually assigned 9 65
Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now