Mschart控件谁会用啊!高分相送啊!

yzcjie 2001-12-04 09:34:36
在asp中怎么使用Mschart这个控件,用它来把数据库中的内容以图形显示出来,希望能给出一段完整的代码,高分相送啊!
...全文
179 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangtou 2001-12-04
  • 打赏
  • 举报
回复
到微软的MSDN网站,键入chart关键字,你就能获得一堆资料。
liaogs 2001-12-04
  • 打赏
  • 举报
回复
看我的!
关于Mschart的说明文档

MsChart是微软制作的功能强大的图表工具,用它可以很方便的建立各种图表。制作各种3维2维的直方图,折线图。结合前一段时间我对Mschart组件的认识,谈谈Mschart组件的使用方法。
1、 Chart Activex控件:
In the HTML page, insert an <OBJECT> tag for the License Manager object before any other <OBJECT> tags. The License Manager is an ActiveX control that is installed with Internet Explorer.
NOTE: This CLASSID, "5220cb21-c88d-11cf-b347-00aa00a28331", is for the License Manager and not for your ActiveX controls. You must use the same CLASSID every time you refer to the LPK file. In addition, you should keep the Name property of the <PARAM> tag as "LPKPath", and set the Value property for the <PARAM> tag of the License Manager object to the LPK file name and path. This path may be a relative path but must not refer to a UNC share or a URL on another domain.
Because you can only have one LPK file for each HTML page, make sure that you include all of the licensed ActiveX Controls for the page when you generate your LPK file. For example:
<object CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331"
id="Microsoft_Licensed_Class_Manager_1_0">
<param NAME="LPKPath" VALUE="mschart.lpk">
</object>
Insert the <OBJECT> tag for your licensed control afterward. For example, an HTML page that displays the Microsoft Masked Edit control looks like this.
Here I downloaded the file mschart.cab from Microsoft's website. It has been digitally signed.
<OBJECT classid="clsid:3A2B370C-BA0A-11D1-B137-0000F8753F5D"
id=mschart1 style="HEIGHT: 326px; WIDTH: 651px" CODEBASE="mschart.cab"></OBJECT>
You can look this acticle if you need help.
http://support.microsoft.com/support/kb/articles/Q159/9/23.ASP
2、 Mschart组件的一些常用属性介绍
a、charttype:图形的类型
charttype=0>三维直方图
charttype=1>二维直方图
charttype=2>三维折线图
charttype=3>二维折线图
charttype=4>三维面积图
charttype=5>二维面积图
charttype=14>饼图
b、showlegend:是否显示解说
c、titletext:标题
d、Columncount: The number of data columns
e、Rowcount:The number of data rows
f、Footnotetext:The footnote text.
g、Plot: Returns a reference to a Plot object that describes the area upon which a chart is displayed.
h、row: A row number in the current column. Rows are numbered from top to bottom beginning with 1. column: The current data column.
i、Rowlabel: The text for a row label. The label you specify sets the label for the data points identified by the Row property. This label appears along the category axis for most chart types and is used as the label for each individual pie in a pie chart. Label text may not be displayed if it is too long to fit on a chart.columnlabel: . Label text associated with a column in the data grid.
j、Data: The data point value. If the current data point already contains a value, it is replaced by the new value. The chart is redrawn to reflect the new value for the current data point.
k、ChartData: A two-dimensional array that holds the data used to draw the chart. If the first series of a multi-dimensional array contains strings, those strings will become the labels of the chart.ChartData is the default property for the MSChart control.
It is so many properities about Mschart Activex.I only introduce so much.Now,I will provide your two example to you!I wish it can help you understand it.
Example 1:It come from:
http://www.4guysfromrolla.com/webtech/MSChartExample.shtm
<object CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331"
id="Microsoft_Licensed_Class_Manager_1_0">
<param NAME="LPKPath" VALUE="mschart.lpk">
</object>
<OBJECT classid="clsid:3A2B370C-BA0A-11D1-B137-0000F8753F5D"
id=mschart1 style="HEIGHT: 326px; WIDTH: 651px" CODEBASE="mschart.cab"></OBJECT>
<script LANGUAGE="Vbscript">
MSChart1.ChartType =1
MSChart1.Plot.SeriesCollection(1).Pen.VtColor.Set 0,0,0
MSChart1.Plot.SeriesCollection(1).Pen.Width = 50
For i = 1 To MSChart1.Plot.Axis(1).Labels.Count
MSChart1.Plot.Axis(1).Labels(i).Format = "$0,###"
MSChart1.Plot.Axis(1).Labels(i).VtFont.Name = "Tahoma"
MSChart1.Plot.Axis(1).Labels(i).VtFont.Size = 10
Next
MSChart1.RowCount = 5
MSChart1.ColumnCount =2
MSChart1.ShowLegend = True
for y = 1 to 2
for x = 1 to 5
MSChart1.Row = x
MsChart1.Column= y
MSChart1.RowLabel = "Row " & x
call MSChart1.DataGrid.SetData(x, 1, x*5,nullFlag)
call MSChart1.DataGrid.SetData(x, 2, x*10,nullFlag)
next
Mschart1.ColumnLable=y
next
</script>
Example 2:We almost can see it everywhere.
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function window_onload()
{
t=0;
mschart1.TitleText = "标题";
mschart1.ShowLegend =true;
mschart1.ColumnCount =2;
mschart1.RowCount =3;
for (i=0;i<3;i++)
{for (j=0;j<2;j++)
{ mschart1.Row=i+1;
mschart1.Column=j+1;
if (2>1)
mschart1.ColumnLabel =document.form1.cname(j).value;
else
mschart1.ColumnLabel =document.form1.cname.value;
if ((document.form1.rcount.value*document.form1.ccount.value)>1)
mschart1.Data=document.form1.rc_data(t).value;
else
mschart1.Data=document.form1.rc_data.value;
t++;
}
if (document.form1.rcount.value>1)
mschart1.RowLabel =document.form1.rname(i).value ;
else
mschart1.RowLabel =document.form1.rname.value;
}
}
function select1_onchange() {
mschart1.chartType =select1.value
mschart1.Plot
}
//-->
</SCRIPT>
<TITLE>数据显示图</TITLE>
</HEAD>
<BODY LANGUAGE=javascript onload="return window_onload()">
<object CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331"
id="Microsoft_Licensed_Class_Manager_1_0">
<param NAME="LPKPath" VALUE="mschart.lpk">
</object>
<OBJECT classid="clsid:3A2B370C-BA0A-11D1-B137-0000F8753F5D"
id=mschart1 style="HEIGHT: 326px; WIDTH: 651px" CODEBASE="mschart.cab"></OBJECT>
<BR>
显示方式
<SELECT id=select1 name=select1 LANGUAGE=javascript onchange="return select1_onchange()">
<OPTION value=1>二维直方图</OPTION>
<OPTION value=0>三维直方图</OPTION>
<OPTION value=3>二维折线图</OPTION>
<OPTION value=2>三维折线图</OPTION>
<OPTION value=5>二维面积图</OPTION>
<OPTION value=4>三维面积图</OPTION>
<OPTION value=14>饼图</OPTION></SELECT>
<!
chtitle 标题
rcount 列数
ccount 行数
rc_type 排列方式(1 以行方式,2以列方式)
rc_data 数据
rname 列名数组
cname 行名数组>
<form name=form1 id=form1>
<input type="hidden" name=rname id=rname value=1993>
<input type="hidden" name=rname id=rname value=1996>
<input type="hidden" name=rname id=rname value=1999>
<input type="hidden" name=cname id=cname value=身高>
<input type="hidden" name=cname id=cname value=体重>
<input type="hidden" name=rcount id=rcount value=3>
<input type="hidden" name=chtitle id=chtitle value=CoolFatMan的成长里程>
<input type="hidden" name=ccount id=ccount value=2>
<input type="hidden" name=rc_data id=rc_data value=179>
<input type="hidden" name=rc_data id=rc_data value=160>
<input type="hidden" name=rc_data id=rc_data value=180>
<input type="hidden" name=rc_data id=rc_data value=170>
<input type="hidden" name=rc_data id=rc_data value=182>
<input type="hidden" name=rc_data id=rc_data value=182>
</form></BODY></HTML>
If you want to run these two examples on your machine.I advised you copy the code and paste on the notepad first!Then save as .asp or .html file.If you have any question,pelase contact with me.Email:wzixing@163.net.
theng 2001-12-04
  • 打赏
  • 举报
回复
julyclyde说的对,下面是完整例程。
哈哈,给分!

<%
response.buffer=true
%>
<!--#include virtual="/map/functions.asp"-->
<%
validateuser
if trim(request.form("textDateScale")) = "" then
session("dateScale") = "14"
else
session("dateScale") = trim(request.form("textDateScale"))
end if
%>

<object id=msodsc classid=CLSID:0002E530-0000-0000-C000-000000000046 width="16" height="15">
</object>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
</head>

<p align="center" style="line-height: 100%"><font face="隶书" size="6" color="#000000">变电站</font><font face="隶书" size="6" color="#000000">设备故障统计图表</font>
<div align="center">

<form method="POST" action="chart.asp" name="form1">
<table border="0" width="100%" bgcolor="#003399">
<tr>
<td width="27%">
<p align="right"><font face="宋体" size="2" color="#FFFFFF">请选择图表类型:</font></td>
<center>
<td width="6%"><font face="宋体" size="2" color="#FFFFFF">
<select name="selChartType" size="1" onChange="selChange()">
<option value="0" selected>列状图</option>
<option value="3">栏状图</option>
<!--
<option value="6">平滑曲线图</option>
<option value="18">饼形图</option>
<option value="29">面积图</option>
-->
</select>

</font></td>
</center>

<td width="15%">
<p align="right"><font face="宋体" size="2" color="#FFFFFF">时间范围:</font></p>
</td>
<td width="19%">

<p align="left"><font face="宋体" size="2" color="#FFFFFF"><input type="text" name="textDateScale" size="5" value="<%=session("dateScale")%>">(天)<input type="button" value="确定" name="ok" onClick="validateInput()"></font></p>
</td>

</tr>
</table>
</form>
</div>
<hr>
<p align="center">

<object id=ChartSpace1 classid=CLSID:0002E500-0000-0000-C000-000000000046 codebase="msowc.dll" width="641" height="251">
</object>

<%
set conn=server.createobject("adodb.connection")
conn.open application("dblogin")
sql="select s.stationID, max(s.stationName) stationName, count(*) as errCount from tblErrorReport as e right outer join tblStation as s On e.stationID = s.stationID where dateDiff(day,e.CheckTime,getDate())<="
sql=sql & session("dateScale")
sql=sql & " group by s.stationID"
'response.write(sql)
set rs=server.createobject ("adodb.recordset")
set rs=conn.execute(sql)
%>

<script language=VBScript>
Sub Window_OnLoad()
Dim categories(99), values(0)

categories(0) = ""

ChartSpace1.Clear

ChartSpace1.Charts.Add

Set c = ChartSpace1.Constants

<%
i = 0
dim gt100
while not rs.eof
%>
ChartSpace1.Charts(0).SeriesCollection.Add
<%
errCount = rs("errCount")
if errCount > 100 then
errCount = errCount / 100
gt100=1
else
gt100=0
end if
%>
values(0) = <%=errCount%>
ChartSpace1.Charts(0).SeriesCollection(<%=i%>).Caption = "<%=trim(rs("stationName"))%>"
ChartSpace1.Charts(0).SeriesCollection(<%=i%>).SetData c.chDimCategories, c.chDataLiteral, categories
ChartSpace1.Charts(0).SeriesCollection(<%=i%>).SetData c.chDimValues, c.chDataLiteral, values
<%
i = i + 1
rs.MoveNext
wend
rs.close
conn.close
set rs= nothing
set conn= nothing
%>

ChartSpace1.Charts(0).HasLegend = True
ChartSpace1.Charts(0).hastitle=true
ChartSpace1.Charts(0).axes(c.chAxisPositionLeft).hastitle=true
ChartSpace1.Charts(0).axes(c.chAxisPositionLeft).title.caption="故障个数<%if gt100=1 then response.write("(百)") end if%>"
'ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft).NumberFormat = "0.##"
ChartSpace1.Charts(0).axes(c.chAxisPositionBottom).hastitle=true
ChartSpace1.Charts(0).axes(c.chAxisPositionBottom).title.caption="站"
ChartSpace1.Charts(0).Title.Font.Name = "宋体"
ChartSpace1.Charts(0).Title.Font.size=12 '标题字体大小
ChartSpace1.Charts(0).Title.caption="故障比较"
ChartSpace1.Charts(0).Type = 0
ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft).NumberFormat = "000"
ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft).MajorUnit = 100
ChartSpace1.Charts(0).Legend.Font.Name = "宋体"
ChartSpace1.Charts(0).Legend.Font.size=10

End Sub

sub selChange()
ChartSpace1.Charts(0).type=form1.selChartType(form1.selChartType.selectedIndex).value
end sub

sub validateInput()

bValid = "true"
data = trim(form1.textDateScale.value)

if isNumeric(data) then
if data>=0 AND data<=9999 then
bValid ="true"
else
bValid ="false"
end if
else
bValid = "false"
end if

if bValid = "false" then
window.alert("请输入有效数字(0~9999)!" )
form1.textDateScale.focus()
else
form1.submit()
end if

end sub
</script>


</p>
julyclyde 2001-12-04
  • 打赏
  • 举报
回复
ASP中无法使用。客户端才可以
http://www.csdn.net/expert/topic/356/356644.shtm

28,405

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧