程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> ASP技巧 >> 如何用ASP建立圖表

如何用ASP建立圖表

編輯:ASP技巧

現在我們針對Excel舉另外一個例子,大家都詢問如何用ASP建立圖表的問題,以下就是解決方案

First we set the type of script
首先設定腳本類型
<%@ LANGUAGE="VBSCRIPT" %>

Make the object, and set the object to an Excelsheet
建立Excelsheet對象

Dim MyExcelChart
Set MyExcelChart = CreateObject("Excel.Sheet")

' show or dont show Excel to user, TRUE or FALSE
是否讓用戶看到Excel表格,真或假
MyExcelChart.application.Visible = True

' populate the cells
添Excel表格
MyExcelChart.ActiveSheet.Range("B2:k2").Value = Array("Week1", "Week2", "Week3", "Week4", "Week5", "Week6", "Week7", "Week8", "Week9", "Week10")
MyExcelChart.ActiveSheet.Range("B3:k3").Value = Array("67", "87", "5", "9", "7", "45", "45", "54", "54", "10")
MyExcelChart.ActiveSheet.Range("B4:k4").Value = Array("10", "10", "8", "27", "33", "37", "50", "54", "10", "10")
MyExcelChart.ActiveSheet.Range("B5:k5").Value = Array("23", "3", "86", "64", "60", "18", "5", "1", "36", "80")
MyExcelChart.ActiveSheet.Cells(3,1).Value="Internet Explorer"
MyExcelChart.ActiveSheet.Cells(4,1).Value="Netscape"
MyExcelChart.ActiveSheet.Cells(5,1).Value="Other"

' Select the contents that need to be in the chart
在Excel表中選擇要在圖表(CHART)中顯示的數據
MyExcelChart.ActiveSheet.Range("b2:k5").Select
  
' Add the chart
加載圖表(CHART)
MyExcelChart.Charts.Add
' Format the chart, set type of chart, shape of the bars, show title, get the data for the chart, show datatable, show legend
初始化圖表(CHART),設定圖表類型,棒圖的形狀,要顯示的標題,取得要作圖的數據,顯示數據表,顯示圖表
MyExcelChart.activechart.ChartType = 97
MyExcelChart.activechart.BarShape =3
MyExcelChart.activechart.HasTitle = True
MyExcelChart.activechart.ChartTitle.Text = "Visitors log for each week shown in browsers percentage"
MyExcelChart.activechart.SetSourceData MyExcelChart.Sheets("Sheet1").Range("A1:k5"),1
MyExcelChart.activechart.Location 1
MyExcelChart.activechart.HasDataTable = True
MyExcelChart.activechart.DataTable.ShowLegendKey = True

' Save the the excelsheet to Excelface
存入Excel表
MyExcelChart.SaveAs "c:\chart.xls"
%>

Now lets complete the Html tags.
下面是Html代碼

<Html>
<HEAD>
<TITLE>MyExcelChart</TITLE>
</HEAD>
<BODY>
</BODY>
</Html>

This completes yer ASP page, look below for the complete code of myExcelchart.ASP
下面是源程序myExcelchart.ASP的完整代碼

<%@ LANGUAGE="VBSCRIPT" %>
<%
Set MyExcelChart = CreateObject("Excel.Sheet")

MyExcelChart.Application.Visible = True

MyExcelChart.ActiveSheet.Range("B2:k2").Value = Array("Week1", "Week2", "Week3", "Week4", "Week5", "Week6", "Week7", "Week8", "Week9", "Week10")
MyExcelChart.ActiveSheet.Range("B3:k3").Value = Array("67", "87", "5", "9", "7", "45", "45", "54", "54", "10")
MyExcelChart.ActiveSheet.Range("B4:k4").Value = Array("10", "10", "8", "27", "33", "37", "50", "54", "10", "10")
MyExcelChart.ActiveSheet.Range("B5:k5").Value = Array("23", "3", "86", "64", "60", "18", "5", "1", "36", "80")
MyExcelChart.ActiveSheet.Cells(3,1).Value="Internet Explorer"
MyExcelChart.ActiveSheet.Cells(4,1).Value="Netscape"
MyExcelChart.ActiveSheet.Cells(5,1).Value="Other"

MyExcelChart.ActiveSheet.Range("b2:k5").Select
  
MyExcelChart.Charts.Add
MyExcelChart.activechart.ChartType = 97
MyExcelChart.activechart.BarShape =3
MyExcelChart.activechart.HasTitle = True
MyExcelChart.activechart.ChartTitle.Text = "Visitors log for each week shown in browsers percentage"
MyExcelChart.activechart.SetSourceData MyExcelChart.Sheets("Sheet1").Range("A1:k5"),1
MyExcelChart.activechart.Location 1
MyExcelChart.activechart.HasDataTable = True
MyExcelChart.activechart.DataTable.ShowLegendKey = True

MyExcelChart.SaveAs "c:\chart.xls"

%>
<Html>
<HEAD>
<TITLE>MyExcelChart</TITLE>
</HEAD>
<BODY>
</BODY>
</Html>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved