Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

charting 1

Status
Not open for further replies.

chinedu

Technical User
Mar 7, 2002
241
US
Hello gurus,
I need an urgent / serious help.
I am looking for a chart/graph or even a pie chart that calculates how many tasks an completes in a month.
So the graph will be looking at taskname, employee name, number of tasks completed and the month.
Eventually, this will be tallied to get the total for a year but we are not worried about that now, although it won't hurt if it is available.
Thanks very much
 
So your looking for software that has already been written or pointers on how to write your own graphing functions?

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
hi guys!
sorry, last time i checked, there was no response.
So I didn't check again and didn't check my email till now.
In any case Tarwn, if one has been writen, I sure can use it and modify to do what we need it to do as long as it is database-driven.
guitardave78, I will check the software out.
If it is not free, we probably won't go for it, that is my hunch.
 
I think Haneng.com has a package also...not sure if it is free or not, last time I need a bar chart I wrote one :p

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 


Heres some example code, I'll try and find the final graph I coded

<%
'---------------------Values-----------------
Dim Title(7) 'Group title, can have HTML tags
Title(1) = &quot;Graph 1&quot;
Title(2) = &quot;Graph 2&quot;
Title(3) = &quot;Graph 3&quot;
Title(4) = &quot;Graph 4&quot;
Title(5) = &quot;Graph 5&quot;
Title(6) = &quot;Graph 6&quot;
Title(7) = &quot;Graph 7&quot;

Dim Values(7, 4)
Dim i(7, 4) 'i(Group#, 1st/2nd Bar)
i(1, 1) = 3000
i(1, 2) = 4300
i(1, 3) = 4360
i(2, 1) = 5300
i(2, 2) = 400
i(2, 3) = 4000
i(3, 1) = 40000
i(3, 2) = 35000
i(3, 3) = 45000
i(4, 1) = 30000
i(4, 2) = 25000
i(4, 3) = 45000
i(5, 1) = 20000
i(5, 2) = 15000
i(5, 3) = 45000
i(6, 1) = 10000
i(6, 2) = 5000
i(6, 3) = 45000
i(7, 1) = 4000
i(7, 2) = 34000
i(7, 3) = 400


Maxvalue = 50000
TopPadding = 30
SidePadding = 100
GroupPadding = 91
BarPadding = 20
Barwidth = 30
LineLengths = 83
'---------Advanced-----------------------------

NumGroups = 6 'Must be the same as or lower than i(x, 3)
'Must be the same as or lower than Title(x)
'Must assign values

NumBars = 2 'Must be the same as or lower than i(6, x)
'Must have colour(from 1 to numbars).gif
'Must assign values
'Numbars * Numgroups must not be more than 18... Limitations on style classes.

%>
 
Ahh I went onto xml/Falsh to make animated graphs.
If you want a zip of this mail me (r_craig@auto-systems.co.uk)
 
It is data driven, ie you give it the data the way it wants it and it takes it and makes a pretty graph for you. You'll have to work out how to get the data out of the database and send it to the graph object.

This is actually a quite nice graph object, kind of what I wanted my old pseudo graph object to be when it grew up :p

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
hi Tarwn,
I can come up with the code but where in the code do you think I should place this code?
Sorry for the cheap question.
 
If you look at the example code that is posted at the bottom of the chart page you should see the sections &quot;Fill aChartXAxisDataLabel&quot; through &quot;Fill aChartLegendSeriesLabel.
&quot;

What you will want to do is use your recordset to create these values dynamically. This is going to require that you get the size of your recordset before processing, as you will need to have the sizes so you can set the aray bounds for the labels and data. This process is going to vary depending on the database set up so i can't really give to thorough an example, but here is a small one:
Code:
Pretend we have 1 Table called UnitSales (this should look familiar)
This imaginary table has many fields, among them are:
sales_month, sales_city, sales_amount

Now in order to create the graph we will need to get all of the data back into a recordset, figure out the bounds or the arrays, and then populate the arrays for the chart.

Here we go:[code]
<%
Option Explicit
Response.Expires = -1000 ' Make browser not cache pg.
Response.Buffer = True ' Buffer content.

Dim strConnect
strConnect = &quot;you connection string&quot;

Dim sql_data, rs_data, conn
sql_data = &quot;SELECT sales_month, sales_city, sales_amount FROM UnitSales ORDER BY sales_month, sales_city&quot;

Set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open strConnect
Set rs_data = conn.Execute sql_data

'normally at this point I would create an array using GetRows and get rid of my ADO objects for quicker more efficient code, but I will stick with the Recordset in the interest of keeping complexity to a minimum

'Now we need to create the variables for the chart and start the page
%>
<!--#include file=&quot;jpsutilityabbr.asp&quot;-->
<!--#include file=&quot;jpschart.asp&quot;-->
<html>
<head>
<title>Bar Chart Short Example</title>
</head>
<body>
<%
' Dim var.
Dim objjpsvbChart
Dim aChartXAxisDataLabel(3)
Dim aChartData(2, 3)
Dim aChartLegendSeriesLabel(2)

'Now we are going to either need to determine the bounds and redim the arrays, or we could strt looping through the recordset adding data and only redim if we need more space, I oprefer to count once, redim once, then populate because I am allergic to redim statements inside loops

'we are going to assume there is data in the recordset, normally you would check for EOF first
Dim cityCount, monthCount
Dim fMonth, tMonth
rs_Data.MoveFirst
Do Until rs_data.EOF
   'check if this is the same month as the last loop, if not then count it
   If tMonth <> rs_data(&quot;sales_month&quot;) Then
      'if this is the first month, then keep track of it for later
      If tMonth = &quot;&quot; Then fMonth = rs_data(&quot;sales_month&quot;)
      monthCount = monthCount + 1
      tMonth = rs_Data(&quot;sales_month&quot;)
   End If

   'city is more complicated as there will be a set for each month, we will just be reading the first month and assuming that all cities will have figures for all months. Normally we wouldn't make this assumption.

   'basically we will just count all the entries in this month, assuming each one is a differant city
   If rs_data(&quot;sales_month&quot;) = fMonth Then
      cityCount = cityCount + 1
   End If
  
   rs_data.MoveNext
Loop

'Now we redim the arrays to the correct size
Dim aChartXAxisDataLabel(monthCount-1)
Dim aChartData(cityCount-1,monthCount-1)
Dim aChartLegendSeriesLabel(cityCount-1)

'Now we need to fill out the data
'   to do this I am going to combine all three sections so we can do it in a single loop
rs_data.MoveFirst

'empty the tMonth variable, keep the fMonth variable
tMonth = &quot;&quot;
'empty the counts
cityCount = 0
monthCount = 0

Do Until rs_data.EOF
   'first check if we need to add a city label
   If tMonth <> rs_data(&quot;sales_month&quot;) Then
      aChartXAxisDataLabel(monthCount) = rs_data(&quot;sales_month&quot;)
      monthCount = monthCount + 1
      'we need to reset the cityCount to 0 for later use as data array index
      cityCount = 0
   End if

   'if this is the first month we will need to add the city labels
   If fMonth = rs_data(&quot;sales_month&quot;) Then
      aChartLegendSeriesLabel(cityCount) = rs_data(&quot;sales_city&quot;)
   End If

   'we increment the city count ouside of the if statement because we will need it for the index of the data array
   cityCount = cityCount + 1

   'Now lets add the data to the correct location
   aChartData(cityCount, monthCount)

   rs_data.MoveNext
Loop

'now we just output the other information for the chart, the database portion is done so we can close out our ADO objects
Set rs_data = Nothing
conn.Close
Set conn = Nothing

 Create, use, destroy chart object.
' (To print, set browser to print background colors.)
Set objjpsvbChart = New jpsvbChart
objjpsvbChart.ChartDataAreaHeight = 200 ' Optional.
objjpsvbChart.ChartDataAreaWidth = 400 ' Optional.
objjpsvbChart.ChartAlignOnPage = &quot;center&quot; ' Optional.
objjpsvbChart.TitleLine1 = &quot;Unit Sales&quot; ' Optional.
objjpsvbChart.TitleLine2 = &quot;1/1/2001 - 4/30/2001&quot; ' Optional.
objjpsvbChart.YAxisLabel = &quot;Sales&quot; ' Optional.
objjpsvbChart.XAxisDataLabelArray = aChartXAxisDataLabel ' Optional.
objjpsvbChart.DataArray = aChartData
objjpsvbChart.DataNumberPrefix = &quot;$&quot; ' Optional.
objjpsvbChart.DataNumberUseCommaSeparator = True ' Optional.
objjpsvbChart.DataNumberDecimalPlaces = 0 ' Optional.
objjpsvbChart.LegendSeriesLabelArray = aChartLegendSeriesLabel ' Optional.
objjpsvbChart.FooterLine1 = &quot;Month&quot; ' Optional.
objjpsvbChart.FooterLine2 = &quot;Latest preliminary figures&quot; ' Optional.
Call objjpsvbChart.Execute()
Set objjpsvbChart = Nothing
%>

Another possibility for the arrays would be to add all of the items to one of two strings with the delimiter of choice, then you could Redim the data array using the UBounds from the two arrays created by splitting on that chosen delimiter.

Anyways, hope this helps,

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
very impressive, very impressive Tarwn!!
It is even more impressive that you took your time to do this.
I truly appreciate it.
--ch
 
...but I am running into some bugs.
One: Name redefined
Chart.asp, line 60, column 4
Dim aChartXAxisDataLabel(monthCount-1)
which is here:
'Now we redim the arrays to the correct size
Dim aChartXAxisDataLabel(monthCount-1)
Dim aChartData(cityCount-1,monthCount-1)
Dim aChartLegendSeriesLabel(cityCount-1)

when I changed them to this:
'Now we redim the arrays to the correct size
reDim aChartXAxisDataLabel(monthCount-1)
reDim aChartData(cityCount-1,monthCount-1)
reDim aChartLegendSeriesLabel(cityCount-1),
I get this:
Microsoft VBScript runtime (0x800A000A)
This array is fixed or temporarily locked

I am also getting this:

Microsoft VBScript runtime (0x800A000D)
Type mismatch on line 92 which is here: 'Now lets add the data to the correct location
aChartData cityCount, monthCount




 
Argh, yes that should have been ReDim's not Dims, sorry about that.

and this line:
Code:
aChartData(cityCount, monthCount)

should have been
Code:
aChartData(cityCount, monthCount) = rs_data(&quot;sales_amount&quot;)

I didn't exactly write this slowly or set up a database to test it :p

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
umm.. Tarwn = errors [lol]

had to do it!!

_________________________________________________________
$str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
$Nstr = ereg_replace(&quot;sleep&quot;,&quot;coffee&quot;,$str); echo $Nstr;

onpnt2.gif
[/sub]
 
hi Tarwn, thanks again for the help.
I am still getting this:
This array is fixed or temporarily locked.
This is happening on the redims.
I have created a db with the same table object and same fields, although I will be using a different table and fields but my thinking is if this works, I all I need to do is change the names, that's all.
Onpnt, you are good too.
I have been helped by both of you before and by a whole lot more folks in this forum.
I believe this forum has the best collection of talents.
 
<<
This is actually a quite nice graph object, kind of what I wanted my old pseudo graph object to be when it grew up :p

-Tarwn
>>

Thanks a lot Tarwn!!! :)

Best regards,
J. Paul Schmidt - Freelance ASP Web Developer
- Creating &quot;dynamic&quot; Web pages that read and write from databases...
 
Hmmm...
Sorry I had another mistake in there. You need to change the initial array declarations to a non-fixed declaration. Basically this means declaring they are arrays but not bothering to declare their sizes. Blame it on the copy and paste :p

Code:
change:
Dimm aChartXAxisDataLabel(3)
Dim aChartData(2, 3)
Dim aChartLegendSeriesLabel(2)

to:
m aChartXAxisDataLabel()
Dim aChartData()
Dim aChartLegendSeriesLabel()

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top