利用Office Chart 制作柱图(两个柱子)
环境:VS.NET 2003 、Office 2003
语言:VBScript 、C#
步骤:
1.单击“工具箱-添加/移除项”,弹出“自定义工具箱”;
2.点击“COM组件”,选择“Microsoft Office Chart 11.0”然后确定,此时工具栏上出现“Microsoft Office Chart 11.0”的图标;
3..aspx的后台代码如下:
html代码
<html>
<head>
<title>OfficeChart3</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server"></form>
<OBJECT id="ChartSpace1" style="Z-INDEX: 101; LEFT: 40px; WIDTH: 432px; POSITION: absolute; TOP: 40px; HEIGHT: 280px"
classid="clsid:0002E55D-0000-0000-C000-000000000046" VIEWASTEXT>
<PARAM NAME="XMLData" VALUE='<xml xmlns:x="urn:schemas-microsoft-com:office:excel"> <x:ChartSpace> <x:OWCVersion>11.0.0.5531 </x:OWCVersion> <x:Width>11430</x:Width> <x:Height>7408</x:Height> <x:Palette> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#8080FF</x:Entry> <x:Entry>#802060</x:Entry> <x:Entry>#FFFFA0</x:Entry> <x:Entry>#A0E0E0</x:Entry> <x:Entry>#600080</x:Entry> <x:Entry>#FF8080</x:Entry> <x:Entry>#008080</x:Entry> <x:Entry>#C0C0FF</x:Entry> <x:Entry>#000080</x:Entry> <x:Entry>#FF00FF</x:Entry> <x:Entry>#80FFFF</x:Entry> <x:Entry>#0080FF</x:Entry> <x:Entry>#FF8080</x:Entry> <x:Entry>#C0FF80</x:Entry> <x:Entry>#FFC0FF</x:Entry> <x:Entry>#FF80FF</x:Entry> </x:Palette> <x:DefaultFont>宋体</x:DefaultFont> </x:ChartSpace> </xml>'>
<PARAM NAME="ScreenUpdating" VALUE="-1">
<PARAM NAME="EnableEvents" VALUE="-1">
</OBJECT>
</FONT>
<script language="vbscript">
Dim categories, values1,values2
categories = "0"+chr(9)+"1"+chr(9)+"2"+chr(9)+"3"+chr(9)+"4"+chr(9)
values1 = "2"+chr(9)+"2"+chr(9)+"3"+chr(9)+"4"+chr(9)+"2"+chr(9)
values2 = "1"+chr(9)+"8"+chr(9)+"0"+chr(9)+"2"+chr(9)+"9"+chr(9)
ChartSpace1.Charts.Add
Set c = ChartSpace1.Constants
ChartSpace1.Charts(0).hastitle=true
ChartSpace1.Charts(0).Title.Font.Name = "仿宋_GB231280"
ChartSpace1.Charts(0).Title.Font.size=12
ChartSpace1.Charts(0).Title.caption="某某业务分析表"
ChartSpace1.Charts(0).HasLegend = True
ChartSpace1.Charts(0).type=c.chChartTypeColumnClustered
ChartSpace1.Charts(0).SetData c.chDimCategories, c.chDataLiteral,categories
'系列0
ChartSpace1.Charts(0).SeriesCollection(0).Caption="数据1" '系列0的图例
ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimValues, c.chDataLiteral, values1
ChartSpace1.Charts(0).SeriesCollection(0).Border.Color="#000000"
ChartSpace1.Charts(0).SeriesCollection(0).Interior.Color="#ff0000"
'系列1
ChartSpace1.Charts(0).SeriesCollection.Add
ChartSpace1.Charts(0).SeriesCollection(1).Caption="数据2" '系列1的图例
ChartSpace1.Charts(0).SeriesCollection(1).SetData c.chDimValues, c.chDataLiteral, values2
ChartSpace1.Charts(0).SeriesCollection(1).Border.Color="#0000ff"
ChartSpace1.Charts(0).SeriesCollection(1).Interior.Color="#00ff00"
ChartSpace1.Charts(0).axes(c.chAxisPositionLeft).hastitle=true
ChartSpace1.Charts(0).axes(c.chAxisPositionLeft).title.caption="数量"
ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft).NumberFormat = "0.##"
ChartSpace1.Charts(0).axes(c.chAxisPositionBottom).hastitle=true
ChartSpace1.Charts(0).axes(c.chAxisPositionBottom).title.caption="时间"
</script>
</body>
</html>
<html>
<head>
<title>OfficeChart3</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server"></form>
<OBJECT id="ChartSpace1" style="Z-INDEX: 101; LEFT: 40px; WIDTH: 432px; POSITION: absolute; TOP: 40px; HEIGHT: 280px"
classid="clsid:0002E55D-0000-0000-C000-000000000046" VIEWASTEXT>
<PARAM NAME="XMLData" VALUE='<xml xmlns:x="urn:schemas-microsoft-com:office:excel"> <x:ChartSpace> <x:OWCVersion>11.0.0.5531 </x:OWCVersion> <x:Width>11430</x:Width> <x:Height>7408</x:Height> <x:Palette> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#000000</x:Entry> <x:Entry>#8080FF</x:Entry> <x:Entry>#802060</x:Entry> <x:Entry>#FFFFA0</x:Entry> <x:Entry>#A0E0E0</x:Entry> <x:Entry>#600080</x:Entry> <x:Entry>#FF8080</x:Entry> <x:Entry>#008080</x:Entry> <x:Entry>#C0C0FF</x:Entry> <x:Entry>#000080</x:Entry> <x:Entry>#FF00FF</x:Entry> <x:Entry>#80FFFF</x:Entry> <x:Entry>#0080FF</x:Entry> <x:Entry>#FF8080</x:Entry> <x:Entry>#C0FF80</x:Entry> <x:Entry>#FFC0FF</x:Entry> <x:Entry>#FF80FF</x:Entry> </x:Palette> <x:DefaultFont>宋体</x:DefaultFont> </x:ChartSpace> </xml>'>
<PARAM NAME="ScreenUpdating" VALUE="-1">
<PARAM NAME="EnableEvents" VALUE="-1">
</OBJECT>
</FONT>
<script language="vbscript">
Dim categories, values1,values2
categories = "0"+chr(9)+"1"+chr(9)+"2"+chr(9)+"3"+chr(9)+"4"+chr(9)
values1 = "2"+chr(9)+"2"+chr(9)+"3"+chr(9)+"4"+chr(9)+"2"+chr(9)
values2 = "1"+chr(9)+"8"+chr(9)+"0"+chr(9)+"2"+chr(9)+"9"+chr(9)
ChartSpace1.Charts.Add
Set c = ChartSpace1.Constants
ChartSpace1.Charts(0).hastitle=true
ChartSpace1.Charts(0).Title.Font.Name = "仿宋_GB231280"
ChartSpace1.Charts(0).Title.Font.size=12
ChartSpace1.Charts(0).Title.caption="某某业务分析表"
ChartSpace1.Charts(0).HasLegend = True
ChartSpace1.Charts(0).type=c.chChartTypeColumnClustered
ChartSpace1.Charts(0).SetData c.chDimCategories, c.chDataLiteral,categories
'系列0
ChartSpace1.Charts(0).SeriesCollection(0).Caption="数据1" '系列0的图例
ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimValues, c.chDataLiteral, values1
ChartSpace1.Charts(0).SeriesCollection(0).Border.Color="#000000"
ChartSpace1.Charts(0).SeriesCollection(0).Interior.Color="#ff0000"
'系列1
ChartSpace1.Charts(0).SeriesCollection.Add
ChartSpace1.Charts(0).SeriesCollection(1).Caption="数据2" '系列1的图例
ChartSpace1.Charts(0).SeriesCollection(1).SetData c.chDimValues, c.chDataLiteral, values2
ChartSpace1.Charts(0).SeriesCollection(1).Border.Color="#0000ff"
ChartSpace1.Charts(0).SeriesCollection(1).Interior.Color="#00ff00"
ChartSpace1.Charts(0).axes(c.chAxisPositionLeft).hastitle=true
ChartSpace1.Charts(0).axes(c.chAxisPositionLeft).title.caption="数量"
ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft).NumberFormat = "0.##"
ChartSpace1.Charts(0).axes(c.chAxisPositionBottom).hastitle=true
ChartSpace1.Charts(0).axes(c.chAxisPositionBottom).title.caption="时间"
</script>
</body>
</html>
柱图:
作者:青羽