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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

plotting a Graph 1

Status
Not open for further replies.

vikaskalra

Technical User
Aug 12, 2002
41
GB
Hi Folks,

Am stuck at a problem, need your help ASAP.

The problem : Am using MS Office Web components to generate graph in my ASP pages.

Am able to plot the Line Graph, all I need is to show the Values at all the Points in the Graph, against which the Graph has been made.

Regards,

Vikas
 
It appears from your post you are able to do everything you mentioned. What are you having trouble with?

Thanks,

Gabe
 
Hi Gabe!

You were correct in pointing that I did not word my problem clearly, my problem was

"I need to show the Values at all the Points in the Graph, against which the Graph has been made"

Anyways, I have found the solution and posting it for if anybody needs any help on this in future:

ChartSpace1.Charts(0).SeriesCollection(0).DataLabelsCollection.Add

Using this you can display the Values at all the points in the Graph.

Regards,
Vikas

 
hello Vikas...
i have several questions, since i don't understand how to use excel thru ASP.

may I know how do we link ASP to excel , and how to view that data in excel chart ??
Perhaps you could show me a simple script of you.

email : julianah@astracmg.co.id

Thanks for advance

*JJ26* [peace]
 
Hi Juliana,

Here is an example :

Say you have a report that you are displaying in IE, using <TABLE></TABLE>, now what you want to do is that this entire thing should open up in Excel, in IE too.

The trick lies in the Response.ContentType directive. Using it you can direct the Output to Excel. As specified in the following example :

Response.ContentType = &quot;application/vnd.ms-excel&quot;

You also needed a test page so here it is, just copy and paste it and it will work fine :

<%@ Language=VBScript %>

<%
' Tells the browser to use Excel to open the file
Response.ContentType = &quot;application/vnd.ms-excel&quot;

dim my_name
my_name=&quot;Vikas Kalra&quot;
%>

<!--
<td><font color=&quot;red&quot;>=sum(a2:b2)</font></td>
-->

<table align=center borderColor=white border=0 cellPadding=0 cellSpacing=1 width=&quot;100%&quot; bgcolor=#efefdf>

<tr bgcolor=&quot;blue&quot;>
<td bgcolor=&quot;blue&quot; ><font color=&quot;white&quot;>Name</font></td>
<td bgcolor=&quot;blue&quot;><font color=&quot;white&quot;>Sales</font></td>
<td bgcolor=&quot;blue&quot;><font color=&quot;white&quot;>Commission</font></td>
</tr>
<tr>
<td><%=my_name%></td>
<td>6420</td>
<td>=(B2 * 0.05)</td>
</tr>
<tr>
<td>Laura Callahan</td>
<td>3675</td>
<td>=(B3 * 0.05)</td>
</tr>
<tr>
<td>Frank Edwards</td>
<td>3840</td>
<td>=(B4 * 0.05)</td>
</tr>
<tr>
<td>Chris Graham</td>
<td>4050</td>
<td>=(B5 * 0.05)</td>
</tr>
<tr>
<td>Owen Ingraham</td>
<td>4750</td>
<td>=(B6 * 0.05)</td>
</tr>
<tr>
<td>Robert King</td>
<td>5290</td>
<td>=(B7 * 0.05)</td>
</tr>
<tr>
<td>Greg Miller</td>
<td>5640</td>
<td>=(B8 * 0.05)</td>
</tr>
<tr>
<td>Ian Ostrander</td>
<td>3965</td>
<td>=(B9 * 0.05)</td>
</tr>
<tr>
<td>Howard Quinn</td>
<td>5865</td>
<td>=(B10 * 0.05)</td>
</tr>
<tr>
<td>Tammy Steel</td>
<td>3570</td>
<td>=(B11 * 0.05)</td>
</tr>
<tr>
<td>Debra Underwood</td>
<td>3790</td>
<td>=(B12 * 0.05)</td>
</tr>
<tr>
<td>Mark White</td>
<td>4500</td>
<td>=(B13 * 0.05)</td>
</tr>
<tr>
<td>Quincy Youngs</td>
<td>4420</td>
<td>=(B14 * 0.05)</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><strong><font color=&quot;blue&quot;>Totals:</font></strong></td>
<td><font color=&quot;red&quot;>=SUM(B2:B14)</font></td>
<td><font color=&quot;red&quot;>=SUM(C2:C14)</font></td>
</tr>
</table>


'Try it and tell me if you face any problems, or need more help on this,

Regards,
Vikas
 
Hi again,

That was Part I of the episode for displaying data in Excel sheet, now if you want to display charts, try this one :-

<%@ Language=VBScript %>
<!--#include file=&quot;adovbs.inc&quot;-->
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>
<object id=ChartSpace1 classid=CLSID:0002E500-0000-0000-C000-000000000046 style=&quot;width:100%;height:350&quot;></object>
<script language=vbs>
Sub Window_OnLoad()
Dim categories, values
categories=&quot;JAN FEB MAR APR MAY JUN&quot;
values=&quot;10 20 30 15 100 40&quot;
values2=&quot;0 15 10 35 80 30&quot;
values3=&quot;5 20 45 35 60 65&quot;

' Create a chart with Multiple series (called &quot;Sales&quot;).
ChartSpace1.Clear
ChartSpace1.Charts.Add
ChartSpace1.Charts(0).SeriesCollection.Add
ChartSpace1.Charts(0).SeriesCollection(0).Caption = &quot;Sales1&quot;
ChartSpace1.Charts(0).SeriesCollection.Add
ChartSpace1.Charts(0).SeriesCollection(1).Caption = &quot;Sales2&quot;
ChartSpace1.Charts(0).SeriesCollection.Add
ChartSpace1.Charts(0).SeriesCollection(2).Caption = &quot;Sales3&quot;

'Set the series categories and values using the strings created above as static currently but can be made dynamically (values, values2,values3).

Set c = ChartSpace1.Constants
ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimCategories, c.chDataLiteral, categories

ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimValues, c.chDataLiteral, values
ChartSpace1.Charts(0).SeriesCollection(1).SetData c.chDimValues, c.chDataLiteral, values2
ChartSpace1.Charts(0).SeriesCollection(2).SetData c.chDimValues, c.chDataLiteral, values3

' Set the chart type
ChartSpace1.Charts(0).Type = c.chChartTypeLineMarkers'chChartTypeBarClustered
ChartSpace1.Charts(0).HasLegend = True
ChartSpace1.Charts(0).Legend.Position = chLegendPositionBottom
ChartSpace1.HasChartSpaceTitle = True
ChartSpace1.ChartSpaceTitle.Caption = &quot;Monthly Sales Analysis&quot;

ChartSpace1.Charts(0).Axes(c.chAxisPositionBottom).hastitle=true
ChartSpace1.Charts(0).Axes(c.chAxisPositionBottom).title.caption=&quot;Months&quot;


ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft).hastitle=true
ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft).title.caption=&quot;Sales&quot;

ChartSpace1.Charts(0).SeriesCollection(0).DataLabelsCollection.Add
ChartSpace1.Charts(0).SeriesCollection(1).DataLabelsCollection.Add
ChartSpace1.Charts(0).SeriesCollection(2).DataLabelsCollection.Add
End Sub
</script>


</BODY>
</HTML>

Please note, in the above example I am showing a Line chart and the data is static. You can also make charts against dynamic data (fetch data from database and simply specify in &quot;values&quot; say something like values= &quot;<%=value_from_database%>&quot; but don't forget to put a tab space between the data values.

hope this helps you,

Regards,
Vikas
 
Sorry for this stupid question.... :->

U ask me to include 1 syntax
Code:
response.contentType
in my ASP file, isn't it ??

and how abt that syntax written in red, i didn't need to write in ASP tag
Code:
<% =sum(a2:b2)%>
???


Code:
<%
' Tells the browser to use Excel to open the file
Response.ContentType = &quot;application/vnd.ms-excel&quot;

dim my_name
my_name=&quot;Vikas Kalra&quot;
%>

<!--
 <td><font color=&quot;red&quot;>
=sum(a2:b2)
Code:
</font></td>
-->

Could you explain more 'cuz im [spin] ... thanks
 
Hi again,

Yes you need to include the Response.ContenType directive.

The following thing :
<!--
<td><font color=&quot;red&quot;>=sum(a2:b2)</font></td>
-->

is a directive for Excel to sum up the columns. So it automatically knows that it has to Sum up a2 and b2 and that the color should be Red.

Secondly you are using <%=my_name%>
this directive is a shortcut we use for Response.Write, so instead of writing :
<%
Response.Write my_name
%>

I am writing :

<%=my_name%>

What I tried to tell you by this was that in case you are using database, you will get some dynamic data values, in that case you will have to use this.

Ok, I think that the previous example was quiet confusing try this one :

<%@ Language=VBScript %>

<%
Response.ContentType = &quot;application/vnd.ms-excel&quot;
my_name=&quot;Vikas Kalra&quot;
%>

<table align=center borderColor=white border=0 cellPadding=0 cellSpacing=1 width=&quot;100%&quot; bgcolor=#efefdf>
<tr bgcolor=&quot;blue&quot;>
<td bgcolor=&quot;blue&quot; ><font color=&quot;white&quot;>Name</font></td>
<td bgcolor=&quot;blue&quot;><font color=&quot;white&quot;>Sales</font></td>
</tr>
<tr>
<td><%=my_name%></td>
<td>6420</td>
</tr>
<tr>
<td>Laura Callahan</td>
<td>3675</td>
</tr>
<tr>
<td>Frank Edwards</td>
<td>3840</td>
</tr>
</table>


... u can always write back if it is still confusing you :)

Regards,
Vikas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top