在前台中提交给OWC一定规则的数据后,可通过脚本生成数据图表,多话不说,前台代码如下:

<%...@ Control Language="C#" AutoEventWireup="true" CodeFile="ViewImage.ascx.cs" Inherits="web_CarsManage_Controls_ViewImage" %>


<script language="javascript">...
<!--
function Ini()

...{
//
// document.form1.all["tbFrom"].readOnly = true;
// document.form1.all["tbTo"].readOnly = true;
var chart = document.getElementById("Chart");//new ActiveXObject("OWC11.ChartSpace.11");
var c = chart.Constants;
if(chart == null)

...{
alert("您没有安装Office!");
}
chart.Clear();
var m_Chart = chart.Charts.Add(0);
//m_Chart.PlotArea.Interior.SetOneColorGradient(c.chGradientVariantStart,c.chGradientVariantStart,0.15, "Silver")
m_Chart.HasLegend = true
//alert('<% =driverList.Count %>');
var j = <% =driverList.Count %>
for(var i=0;i<j;i++)

...{
alert(i.toString());
}
m_Chart.HasTitle = true
m_Chart.Title.Caption = "油耗量统计分析";
m_Chart.Axes(0).HasTitle = true;
m_Chart.Axes(0).Title.Caption = "月份";
m_Chart.Axes(1).HasTitle = true;
m_Chart.Axes(1).Title.Caption = "油耗量";

m_Chart.type=0;
var aCats = ["中国","美国","澳大利亚"];//["1","2","3","4","5","6","7","8","9","10","11","12"];
var aVals = [100, 120, 128]//<% =OilTotal.ToString() %>;//<% =OilTotal %>;;
var oSer = m_Chart.SeriesCollection.Add(0);
oSer.SetData(c.chDimSeriesNames,-1, "标准油耗");
oSer.SetData(c.chDimCategories,-1,aCats);
oSer.SetData(c.chDimValues,-1,aVals);
//var oSer1 = m_Chart.SeriesCollection.Add(0);
var aVals1 = [123,124,145];//<% =OilTotal %>;//[100, 120, 128];
var oser = m_Chart.SeriesCollection.Add(1);
oser.SetData(c.chDimSeriesNames,-1, "图例1");
oser.SetData(c.chDimCategories,-1,aCats);
oser.SetData(c.chDimValues,-1,aVals1);

chart.AllowPropertyToolbox = true;
chart.DisplayToolbar=true;
}

-->
</script>

<body onload="javascript:Ini()">
<table width="100%">
<tr>
<td>
<table width="100%">
<tr>
<td style="width: 250px; text-align: right">年份:</td>
<td style="width: 85px">
<asp:DropDownList ID="ddlYear" runat="server" Width="130px">
</asp:DropDownList>
</td>
<td style="width: 36px; text-align: right" align="right">车号:</td>
<td style="width: 100px">
<asp:DropDownList ID="ddlCnumber" runat="server" Width="130px">
<asp:ListItem>--请选择车号</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 250px; height: 116px;" align="right">驾驶员:</td>
<td style="width: 85px; height: 116px;">
<asp:ListBox ID="lstName" runat="server" Height="130px" Width="130px"></asp:ListBox>
</td>
<td style="width: 36px; height: 116px; text-align: center;" align="right">
<table style="width: 1px">
<tr>
<td style="width: 21px">
<asp:Button ID="btnSelectAll" runat="server" OnClick="btnSelectAll_Click" Text=">>" CssClass="button_skin"
Width="30px" /></td>
</tr>
<tr>
<td style="width: 21px">
<asp:Button ID="btnSelectSingle" runat="server" OnClick="btnSelectSingle_Click" Text=">" CssClass="button_skin"
Width="30px" /></td>
</tr>
<tr>
<td style="width: 21px">
<asp:Button ID="btnRemoveSingle" runat="server" OnClick="btnRemoveSingle_Click" Text="<" CssClass="button_skin"
Width="30px" /></td>
</tr>
<tr>
<td style="width: 21px; height: 26px">
<asp:Button ID="btnRemoveAll" runat="server" OnClick="btnRemoveAll_Click" Text="<<" CssClass="button_skin"
Width="30px" /></td>
</tr>
</table>
</td>
<td style="width:380px; height: 116px;"><asp:ListBox ID="lstSelectName" runat="server" Height="128px" Width="130px"></asp:ListBox></td>
</tr>
<tr>
<td align="center" colspan="4">
<asp:Button ID="btnOK" runat="server" OnClick="btnOK_Click" Text="统计分析" CssClass="button_skin" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="1" rowspan="3" style="width: 730px; text-align: center">
<asp:Image ID="Image1" runat="server" Visible="false"/><object id="Chart" name="Chart" codebase="http://www.smnpc.cn/bin/OWC11.DLL#version=11,0,6555,0"
classid="clsid:0002E55D-0000-0000-C000-000000000046" progid="OWC11.ChartSpace.11"></object></td>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
</body>
