OWC:产品销量统计图
前台HTML部分代码
<HTML>
<HEAD>
<EasyClick:HeaderTitle id="HeaderTitle1" runat="server"></EasyClick:HeaderTitle>
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<SCRIPT type="text/javascript" language="javascript" src="../../Script/Calendar.js"></SCRIPT>
<SCRIPT type="text/javascript" language="javascript">
<!--
function OnSubmit()
{
var s = document.getElementById('txtBeginTime').value;
var e = document.getElementById('txtendTime').value;
if(s=='')
{
alert('统计期间必须明确!');
document.getElementById('txtBeginTime').click();
return false;
}
if(e=='')
{
alert('统计期间必须明确!');
document.getElementById('txtendTime').click();
return false;
}
var arr1 = s.split('-');
var arr2 = e.split('-');
//alert(arr1[0]+'-'+arr1[1]+'-'+arr1[2]);
//var d1 = new Date(arr1[0],arr1[1],arr2[2]);
//var d2 = new Date(arr2[0],arr2[1],arr2[2]);
var num1 = eval(parseInt(arr1[0])*12+parseInt(arr1[1]));
var num2 = eval(parseInt(arr2[0])*12+parseInt(arr2[1]));
var spc = eval(num2-num1);
if(document.getElementById('rdoYear').checked && spc>=60)
{
alert('按年统计不能超过5年!');
return false;
}
if(document.getElementById('rdoQuarter').checked && spc>=24)
{
alert('按季统计不能超过两年!');
return false;
}
if(document.getElementById('rdoMonth').checked && spc>=12)
{
alert('按月统计不能超过12个月!');
return false;
}
return true;
}
//-->
</SCRIPT>
</HEAD>
<!--form body region start-->
<form id="Form1" method="post" runat="server" onsubmit="return OnSubmit();">
<TABLE id="TblCRV" width="100%">
<TR height="20">
<td><fieldset class="easyfield" style="WIDTH:100%"><legend>查询条件</legend>
<table width="100%">
<tr>
<TD class="TD_Left">出库类型</TD>
<TD class="TD_BG" style="WIDTH:20%">
<uc1:selectbox id="selInvType" dblClick="false" runat="server" width="120px"></uc1:selectbox></TD>
<TD class="TD_Left">产品组</TD>
<TD class="TD_BG" style="WIDTH:20%">
<uc1:selectbox id="selGroup" dblClick="false" onSelectChange="" runat="server" width="120px"></uc1:selectbox></TD>
<TD class="TD_Left">产品名称</TD>
<TD class="TD_BG" style="WIDTH:25%"><INPUT class="EasyText" id="txtProductName" type="text" maxLength="100" name="txtProductName"
size="28" runat="server"></TD>
</tr>
<TR>
<TD class="TD_Left">客户名称</TD>
<TD class="TD_BG">
<uc1:selectbox id="selCU" dblClick="false" runat="server" width="120px"></uc1:selectbox></TD>
<TD class="TD_Left">统计项目</TD>
<TD class="TD_BG"><asp:RadioButton id="rdoMoney" runat="server" Text="金额" GroupName="rdoField"></asp:RadioButton>
<asp:RadioButton id="rdoQty" runat="server" Text="数量" GroupName="rdoField"></asp:RadioButton></TD>
<TD class="td_left">统计期间</TD>
<TD class="td_bg"><INPUT class="easytext" id="txtBeginTime" onclick="javascript:setDate(this);" onchange=""
readOnly type="text" size="10" name="txtBeginTime" runat="server" style="CURSOR:pointer">
至 <INPUT class="easytext" id="txtendTime" onclick="javascript:setDate(this);" onchange=""
readOnly type="text" size="10" name="txtendTime" runat="server" style="CURSOR:pointer">
</TD>
</TR>
<TR>
<TD class="TD_Left">统计方式</TD>
<TD class="TD_BG">
<asp:RadioButton id="rdoYear" runat="server" GroupName="rdoDatepart" Text="年"></asp:RadioButton>
<asp:RadioButton id="rdoQuarter" runat="server" GroupName="rdoDatepart" Text="季"></asp:RadioButton>
<asp:RadioButton id="rdoMonth" runat="server" GroupName="rdoDatepart" Text="月"></asp:RadioButton></TD>
<TD class="td_left">视图</TD>
<TD class="TD_BG">
<asp:RadioButton id="rdoRect" runat="server" GroupName="rdoOWC"></asp:RadioButton>
<label for="rdoRect"><img src="../../Image/imgRect.gif" alt="柱状图" Width="20" Height="20"></label>
<asp:RadioButton id="rdoPie" runat="server" GroupName="rdoOWC"></asp:RadioButton>
<label for="rdoPie"><img src="../../Image/imgPie.gif" alt="饼图" Width="20" Height="20"></label>
<asp:RadioButton id="rdoCurve" runat="server" GroupName="rdoOWC"></asp:RadioButton>
<label for="rdoCurve"><img src="../../Image/imgCurve.gif" alt="曲线图" Width="20" Height="20"></label>
</TD>
<TD class="TD_BGRight" colspan="2">
<asp:Button id="btnGO" runat="server" Text="查找"></asp:Button></TD>
</TR>
</table>
</fieldset>
</td>
</TR>
<TR height="20">
<TD>
<asp:datagrid id="dgLend" Width="100%" Runat="server" CssClass="EasyDataGrid">
<FooterStyle CssClass="EasyGridFooter"></FooterStyle>
<HeaderStyle CssClass="EasyGridHeader"></HeaderStyle>
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:datagrid>
</TD>
</TR>
<tr>
<td>
<asp:Image id="imgOWC" runat="server"></asp:Image>
</td>
</tr>
</TABLE>
</form>
<!--form body region end-->
<HTML>
<HEAD>
<EasyClick:HeaderTitle id="HeaderTitle1" runat="server"></EasyClick:HeaderTitle>
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<SCRIPT type="text/javascript" language="javascript" src="../../Script/Calendar.js"></SCRIPT>
<SCRIPT type="text/javascript" language="javascript">
<!--
function OnSubmit()
{
var s = document.getElementById('txtBeginTime').value;
var e = document.getElementById('txtendTime').value;
if(s=='')
{
alert('统计期间必须明确!');
document.getElementById('txtBeginTime').click();
return false;
}
if(e=='')
{
alert('统计期间必须明确!');
document.getElementById('txtendTime').click();
return false;
}
var arr1 = s.split('-');
var arr2 = e.split('-');
//alert(arr1[0]+'-'+arr1[1]+'-'+arr1[2]);
//var d1 = new Date(arr1[0],arr1[1],arr2[2]);
//var d2 = new Date(arr2[0],arr2[1],arr2[2]);
var num1 = eval(parseInt(arr1[0])*12+parseInt(arr1[1]));
var num2 = eval(parseInt(arr2[0])*12+parseInt(arr2[1]));
var spc = eval(num2-num1);
if(document.getElementById('rdoYear').checked && spc>=60)
{
alert('按年统计不能超过5年!');
return false;
}
if(document.getElementById('rdoQuarter').checked && spc>=24)
{
alert('按季统计不能超过两年!');
return false;
}
if(document.getElementById('rdoMonth').checked && spc>=12)
{
alert('按月统计不能超过12个月!');
return false;
}
return true;
}
//-->
</SCRIPT>
</HEAD>
<!--form body region start-->
<form id="Form1" method="post" runat="server" onsubmit="return OnSubmit();">
<TABLE id="TblCRV" width="100%">
<TR height="20">
<td><fieldset class="easyfield" style="WIDTH:100%"><legend>查询条件</legend>
<table width="100%">
<tr>
<TD class="TD_Left">出库类型</TD>
<TD class="TD_BG" style="WIDTH:20%">
<uc1:selectbox id="selInvType" dblClick="false" runat="server" width="120px"></uc1:selectbox></TD>
<TD class="TD_Left">产品组</TD>
<TD class="TD_BG" style="WIDTH:20%">
<uc1:selectbox id="selGroup" dblClick="false" onSelectChange="" runat="server" width="120px"></uc1:selectbox></TD>
<TD class="TD_Left">产品名称</TD>
<TD class="TD_BG" style="WIDTH:25%"><INPUT class="EasyText" id="txtProductName" type="text" maxLength="100" name="txtProductName"
size="28" runat="server"></TD>
</tr>
<TR>
<TD class="TD_Left">客户名称</TD>
<TD class="TD_BG">
<uc1:selectbox id="selCU" dblClick="false" runat="server" width="120px"></uc1:selectbox></TD>
<TD class="TD_Left">统计项目</TD>
<TD class="TD_BG"><asp:RadioButton id="rdoMoney" runat="server" Text="金额" GroupName="rdoField"></asp:RadioButton>
<asp:RadioButton id="rdoQty" runat="server" Text="数量" GroupName="rdoField"></asp:RadioButton></TD>
<TD class="td_left">统计期间</TD>
<TD class="td_bg"><INPUT class="easytext" id="txtBeginTime" onclick="javascript:setDate(this);" onchange=""
readOnly type="text" size="10" name="txtBeginTime" runat="server" style="CURSOR:pointer">
至 <INPUT class="easytext" id="txtendTime" onclick="javascript:setDate(this);" onchange=""
readOnly type="text" size="10" name="txtendTime" runat="server" style="CURSOR:pointer">
</TD>
</TR>
<TR>
<TD class="TD_Left">统计方式</TD>
<TD class="TD_BG">
<asp:RadioButton id="rdoYear" runat="server" GroupName="rdoDatepart" Text="年"></asp:RadioButton>
<asp:RadioButton id="rdoQuarter" runat="server" GroupName="rdoDatepart" Text="季"></asp:RadioButton>
<asp:RadioButton id="rdoMonth" runat="server" GroupName="rdoDatepart" Text="月"></asp:RadioButton></TD>
<TD class="td_left">视图</TD>
<TD class="TD_BG">
<asp:RadioButton id="rdoRect" runat="server" GroupName="rdoOWC"></asp:RadioButton>
<label for="rdoRect"><img src="../../Image/imgRect.gif" alt="柱状图" Width="20" Height="20"></label>
<asp:RadioButton id="rdoPie" runat="server" GroupName="rdoOWC"></asp:RadioButton>
<label for="rdoPie"><img src="../../Image/imgPie.gif" alt="饼图" Width="20" Height="20"></label>
<asp:RadioButton id="rdoCurve" runat="server" GroupName="rdoOWC"></asp:RadioButton>
<label for="rdoCurve"><img src="../../Image/imgCurve.gif" alt="曲线图" Width="20" Height="20"></label>
</TD>
<TD class="TD_BGRight" colspan="2">
<asp:Button id="btnGO" runat="server" Text="查找"></asp:Button></TD>
</TR>
</table>
</fieldset>
</td>
</TR>
<TR height="20">
<TD>
<asp:datagrid id="dgLend" Width="100%" Runat="server" CssClass="EasyDataGrid">
<FooterStyle CssClass="EasyGridFooter"></FooterStyle>
<HeaderStyle CssClass="EasyGridHeader"></HeaderStyle>
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:datagrid>
</TD>
</TR>
<tr>
<td>
<asp:Image id="imgOWC" runat="server"></asp:Image>
</td>
</tr>
</TABLE>
</form>
<!--form body region end-->
。VB后台代码
'**********************************
' 功 能:用户产品销售统计
' 作 者:dzh
' 创建时间:2006-06-05
' 说 明:
'**********************************
Imports System
Imports System.Web.UI
Imports OWC
Imports EasyClick.EasyBusiness '--业务逻辑
Imports EasyClick.EasyEntity '--数据实体
Public Class StatProductOutClass StatProductOut
Inherits Basepage '--继承于BasePage
'页面加载
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Me.rdoQty.Checked = True
Me.rdoMonth.Checked = True
Me.rdoRect.Checked = True
Me.txtBeginTime.Value = Today.AddYears(-1).AddMonths(1).Date
Me.txtendTime.Value = Today.Date
Dim myProductBusiness As New ProductBusiness
Dim mybinder As New Binder
mybinder.IsBlankLine = True
'进出货类型绑定 - 0,入库类型;1,出库类型
mybinder.BindSelObject(Me.selInvType, myProductBusiness.GetInventoryType(Me.UserId, , , , , CInt(CommonBusiness.出库), ))
'产品组绑定
mybinder.BindSelObject(Me.selGroup, Binder.SelObjectEnum.UserProductGroup, Me.UserId, -1, )
'绑定客户
mybinder.BindSelObject(Me.selCU, (New CustomerBusiness).GetCustomerList(Me.UserId))
Me.DGBind()
End If
Me.btnGO.Attributes.Add("onclick", "return OnSubmit();")
Me.rdoPie.Attributes.Add("onclick", "javascript:document.getElementById('btnGO').click();")
Me.rdoRect.Attributes.Add("onclick", "javascript:document.getElementById('btnGO').click();")
Me.rdoCurve.Attributes.Add("onclick", "javascript:document.getElementById('btnGO').click();")
End Sub
'数据绑定
Private Sub DGBind()Sub DGBind()
Dim dPart As ProductBusiness.enumDatepart = ProductBusiness.enumDatepart.m
Dim fld As ProductBusiness.enumStatfield = ProductBusiness.enumStatfield.qty
Dim sDate As Date = CDate(Me.txtBeginTime.Value)
Dim eDate As Date = CDate(Me.txtendTime.Value)
Dim cuid As Long = 0
Dim invType As Long = 0
Dim gid As String = ""
Dim pName As String = ""
If Me.rdoMonth.Checked = True Then
dPart = ProductBusiness.enumDatepart.m
ElseIf Me.rdoQuarter.Checked = True Then
dPart = ProductBusiness.enumDatepart.q
ElseIf Me.rdoYear.Checked = True Then
dPart = ProductBusiness.enumDatepart.y
Else
Throw New ArgumentNullException("统计方式必选")
End If
If Me.rdoMoney.Checked = True Then
fld = ProductBusiness.enumStatfield.money
ElseIf Me.rdoQty.Checked = True Then
fld = ProductBusiness.enumStatfield.qty
Else
Throw New ArgumentNullException("统计项目必选")
End If
If Me.selCU.HiddenValue.Trim() = String.Empty Then
cuid = -1
Else
cuid = CLng(Me.selCU.HiddenValue)
End If
If Me.selInvType.HiddenValue.Trim() = String.Empty Then
invType = -1
Else
invType = CLng(Me.selInvType.HiddenValue)
End If
gid = Me.selGroup.HiddenValue.Trim()
pName = Me.txtProductName.Value.Trim()
''///{ds=::::::::::::::[POST]T-SQL:产品销量统计:::::::::::}
Dim ds As DataSet = (New ProductBusiness).StatProductOut(Me.UserId, dPart, fld, sDate, eDate, cuid, invType, gid, pName)
Me.imgOWC.Visible = False
If ds.Tables(0).Rows.Count > 0 Then
If Not ds.Tables(0).Rows(0).Item(0) Is DBNull.Value Then
Me.imgOWC.Visible = True
Me.CreatePic(ds)
Else
ds.Tables(0).Rows.RemoveAt(0)
End If
With Me.dgLend
.DataSource = ds
.DataBind()
For i As Integer = 0 To ds.Tables(0).Columns.Count - 1
If Me.dgLend.Items(0).Cells(i).Text = 0 Then
Me.dgLend.Items(0).Cells(i).Text = " "
ElseIf Me.rdoMoney.Checked = True Then
Me.dgLend.Items(0).Cells(i).Text = FormatNumber(Me.dgLend.Items(0).Cells(i).Text, 2, TriState.True, TriState.UseDefault, TriState.True)
End If
Next
End With
End If
End Sub
'OWC绘图
Private Sub CreatePic()Sub CreatePic(ByRef ds As DataSet)
'//创建ChartSpace对象来放置图表
Dim owcChartSpace As OWC.ChartSpace = New OWC.ChartSpace
'////在ChartSpace对象中添加图表,Add方法返回chart对象
Dim owcChart As OWC.WCChart = owcChartSpace.Charts.Add
'//指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到
If Me.rdoCurve.Checked = True Then '/chChartTypeSmoothLine 平滑曲线图
owcChart.Type = ChartChartTypeEnum.chChartTypeSmoothLine
ElseIf Me.rdoPie.Checked = True Then '/chChartTypePie 饼图
owcChart.Type = ChartChartTypeEnum.chChartTypePie
Else '/chChartTypeColumnClustered 柱状图
owcChart.Type = OWC.ChartChartTypeEnum.chChartTypeColumnClustered
End If
'//指定图表是否需要图例
owcChart.HasLegend = True
owcChart.Legend.Font.Size = 10
'//给定标题
owcChart.HasTitle = True
owcChart.Title.Caption = "产品" & IIf(Me.rdoQty.Checked = True, "销量", "销售额") & "统计图"
owcChart.Title.Font.Bold = True '粗体
owcChart.Title.Font.Size = 12 '字体大小为12
owcChart.Title.Font.Color = "#FF0000"
'添加一个series
owcChart.SeriesCollection.Add(0)
If Me.rdoPie.Checked = False Then
'//给定x,y轴的图示说明
owcChart.Axes(0).HasTitle = True
owcChart.Axes(0).Title.Caption = "Y : " & IIf(Me.rdoQty.Checked = True, "销量", "销售额")
owcChart.Axes(1).HasTitle = True
owcChart.Axes(1).Title.Caption = "X : " & IIf(Me.rdoMonth.Checked = True, "月份", IIf(Me.rdoYear.Checked = True, "年份", "季度"))
owcChart.Axes(0).Font.Size = 9
owcChart.Axes(1).Font.Size = 9
Else
'显示百分比标签
'DataLabelsCollection表示图表的数据标志,这里就是显示百分比的标签
With owcChart.SeriesCollection.Item(0).DataLabelsCollection.Add
.HasValue = False '因为并行图没有Y轴数据,所以把这个值设置成False
.HasPercentage = True '指定数据标志当前显示其百分比值,该属性只适用于饼图、圆环图和堆积图
.Font.Size = 10 '设置数据标志字体为10象素
.Interior.Color = RGB(255, 255, 255) '数据标志标签背景色为白色
End With
End If
'计算数据
'*categories 和 values 可以用tab分割的字符串来表示*
Dim strSeriesName As String = "图例 1"
Dim strCategory As String = ""
Dim strValue As String = ""
For j As Integer = 0 To ds.Tables(0).Columns.Count - 1
strCategory += (CStr(ds.Tables(0).Columns(j).Caption) + ControlChars.Tab)
strValue += (CStr(ds.Tables(0).Rows(0).Item(j)) + ControlChars.Tab)
Next
'给定series的名字
If Me.rdoPie.Checked = False Then
owcChart.SeriesCollection(0).SetData(ChartDimensionsEnum.chDimSeriesNames, ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName)
End If
'给定分类
owcChart.SeriesCollection(0).SetData(ChartDimensionsEnum.chDimCategories, ChartSpecialDataSourcesEnum.chDataLiteral, strCategory)
'给定值
owcChart.SeriesCollection(0).SetData(ChartDimensionsEnum.chDimValues, ChartSpecialDataSourcesEnum.chDataLiteral, strValue)
'//将OWC处理结果转换成Gif图象输出到浏览器中显示
owcChartSpace.ExportPicture(Server.MapPath("") + "\picOWC.gif", "gif", 770, 350)
'销毁OWC对象
owcChart = Nothing
owcChartSpace.Clear()
'获取图片流
Me.imgOWC.ImageUrl = "ReadPic.aspx"
End Sub
'执行查询
Private Sub btnGO_Click()Sub btnGO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGO.Click
Me.DGBind()
End Sub
End Class
'**********************************
' 功 能:用户产品销售统计
' 作 者:dzh
' 创建时间:2006-06-05
' 说 明:
'**********************************
Imports System
Imports System.Web.UI
Imports OWC
Imports EasyClick.EasyBusiness '--业务逻辑
Imports EasyClick.EasyEntity '--数据实体
Public Class StatProductOutClass StatProductOut
Inherits Basepage '--继承于BasePage
'页面加载
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Me.rdoQty.Checked = True
Me.rdoMonth.Checked = True
Me.rdoRect.Checked = True
Me.txtBeginTime.Value = Today.AddYears(-1).AddMonths(1).Date
Me.txtendTime.Value = Today.Date
Dim myProductBusiness As New ProductBusiness
Dim mybinder As New Binder
mybinder.IsBlankLine = True
'进出货类型绑定 - 0,入库类型;1,出库类型
mybinder.BindSelObject(Me.selInvType, myProductBusiness.GetInventoryType(Me.UserId, , , , , CInt(CommonBusiness.出库), ))
'产品组绑定
mybinder.BindSelObject(Me.selGroup, Binder.SelObjectEnum.UserProductGroup, Me.UserId, -1, )
'绑定客户
mybinder.BindSelObject(Me.selCU, (New CustomerBusiness).GetCustomerList(Me.UserId))
Me.DGBind()
End If
Me.btnGO.Attributes.Add("onclick", "return OnSubmit();")
Me.rdoPie.Attributes.Add("onclick", "javascript:document.getElementById('btnGO').click();")
Me.rdoRect.Attributes.Add("onclick", "javascript:document.getElementById('btnGO').click();")
Me.rdoCurve.Attributes.Add("onclick", "javascript:document.getElementById('btnGO').click();")
End Sub
'数据绑定
Private Sub DGBind()Sub DGBind()
Dim dPart As ProductBusiness.enumDatepart = ProductBusiness.enumDatepart.m
Dim fld As ProductBusiness.enumStatfield = ProductBusiness.enumStatfield.qty
Dim sDate As Date = CDate(Me.txtBeginTime.Value)
Dim eDate As Date = CDate(Me.txtendTime.Value)
Dim cuid As Long = 0
Dim invType As Long = 0
Dim gid As String = ""
Dim pName As String = ""
If Me.rdoMonth.Checked = True Then
dPart = ProductBusiness.enumDatepart.m
ElseIf Me.rdoQuarter.Checked = True Then
dPart = ProductBusiness.enumDatepart.q
ElseIf Me.rdoYear.Checked = True Then
dPart = ProductBusiness.enumDatepart.y
Else
Throw New ArgumentNullException("统计方式必选")
End If
If Me.rdoMoney.Checked = True Then
fld = ProductBusiness.enumStatfield.money
ElseIf Me.rdoQty.Checked = True Then
fld = ProductBusiness.enumStatfield.qty
Else
Throw New ArgumentNullException("统计项目必选")
End If
If Me.selCU.HiddenValue.Trim() = String.Empty Then
cuid = -1
Else
cuid = CLng(Me.selCU.HiddenValue)
End If
If Me.selInvType.HiddenValue.Trim() = String.Empty Then
invType = -1
Else
invType = CLng(Me.selInvType.HiddenValue)
End If
gid = Me.selGroup.HiddenValue.Trim()
pName = Me.txtProductName.Value.Trim()
''///{ds=::::::::::::::[POST]T-SQL:产品销量统计:::::::::::}
Dim ds As DataSet = (New ProductBusiness).StatProductOut(Me.UserId, dPart, fld, sDate, eDate, cuid, invType, gid, pName)
Me.imgOWC.Visible = False
If ds.Tables(0).Rows.Count > 0 Then
If Not ds.Tables(0).Rows(0).Item(0) Is DBNull.Value Then
Me.imgOWC.Visible = True
Me.CreatePic(ds)
Else
ds.Tables(0).Rows.RemoveAt(0)
End If
With Me.dgLend
.DataSource = ds
.DataBind()
For i As Integer = 0 To ds.Tables(0).Columns.Count - 1
If Me.dgLend.Items(0).Cells(i).Text = 0 Then
Me.dgLend.Items(0).Cells(i).Text = " "
ElseIf Me.rdoMoney.Checked = True Then
Me.dgLend.Items(0).Cells(i).Text = FormatNumber(Me.dgLend.Items(0).Cells(i).Text, 2, TriState.True, TriState.UseDefault, TriState.True)
End If
Next
End With
End If
End Sub
'OWC绘图
Private Sub CreatePic()Sub CreatePic(ByRef ds As DataSet)
'//创建ChartSpace对象来放置图表
Dim owcChartSpace As OWC.ChartSpace = New OWC.ChartSpace
'////在ChartSpace对象中添加图表,Add方法返回chart对象
Dim owcChart As OWC.WCChart = owcChartSpace.Charts.Add
'//指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到
If Me.rdoCurve.Checked = True Then '/chChartTypeSmoothLine 平滑曲线图
owcChart.Type = ChartChartTypeEnum.chChartTypeSmoothLine
ElseIf Me.rdoPie.Checked = True Then '/chChartTypePie 饼图
owcChart.Type = ChartChartTypeEnum.chChartTypePie
Else '/chChartTypeColumnClustered 柱状图
owcChart.Type = OWC.ChartChartTypeEnum.chChartTypeColumnClustered
End If
'//指定图表是否需要图例
owcChart.HasLegend = True
owcChart.Legend.Font.Size = 10
'//给定标题
owcChart.HasTitle = True
owcChart.Title.Caption = "产品" & IIf(Me.rdoQty.Checked = True, "销量", "销售额") & "统计图"
owcChart.Title.Font.Bold = True '粗体
owcChart.Title.Font.Size = 12 '字体大小为12
owcChart.Title.Font.Color = "#FF0000"
'添加一个series
owcChart.SeriesCollection.Add(0)
If Me.rdoPie.Checked = False Then
'//给定x,y轴的图示说明
owcChart.Axes(0).HasTitle = True
owcChart.Axes(0).Title.Caption = "Y : " & IIf(Me.rdoQty.Checked = True, "销量", "销售额")
owcChart.Axes(1).HasTitle = True
owcChart.Axes(1).Title.Caption = "X : " & IIf(Me.rdoMonth.Checked = True, "月份", IIf(Me.rdoYear.Checked = True, "年份", "季度"))
owcChart.Axes(0).Font.Size = 9
owcChart.Axes(1).Font.Size = 9
Else
'显示百分比标签
'DataLabelsCollection表示图表的数据标志,这里就是显示百分比的标签
With owcChart.SeriesCollection.Item(0).DataLabelsCollection.Add
.HasValue = False '因为并行图没有Y轴数据,所以把这个值设置成False
.HasPercentage = True '指定数据标志当前显示其百分比值,该属性只适用于饼图、圆环图和堆积图
.Font.Size = 10 '设置数据标志字体为10象素
.Interior.Color = RGB(255, 255, 255) '数据标志标签背景色为白色
End With
End If
'计算数据
'*categories 和 values 可以用tab分割的字符串来表示*
Dim strSeriesName As String = "图例 1"
Dim strCategory As String = ""
Dim strValue As String = ""
For j As Integer = 0 To ds.Tables(0).Columns.Count - 1
strCategory += (CStr(ds.Tables(0).Columns(j).Caption) + ControlChars.Tab)
strValue += (CStr(ds.Tables(0).Rows(0).Item(j)) + ControlChars.Tab)
Next
'给定series的名字
If Me.rdoPie.Checked = False Then
owcChart.SeriesCollection(0).SetData(ChartDimensionsEnum.chDimSeriesNames, ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName)
End If
'给定分类
owcChart.SeriesCollection(0).SetData(ChartDimensionsEnum.chDimCategories, ChartSpecialDataSourcesEnum.chDataLiteral, strCategory)
'给定值
owcChart.SeriesCollection(0).SetData(ChartDimensionsEnum.chDimValues, ChartSpecialDataSourcesEnum.chDataLiteral, strValue)
'//将OWC处理结果转换成Gif图象输出到浏览器中显示
owcChartSpace.ExportPicture(Server.MapPath("") + "\picOWC.gif", "gif", 770, 350)
'销毁OWC对象
owcChart = Nothing
owcChartSpace.Clear()
'获取图片流
Me.imgOWC.ImageUrl = "ReadPic.aspx"
End Sub
'执行查询
Private Sub btnGO_Click()Sub btnGO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGO.Click
Me.DGBind()
End Sub
End Class
'///<summary>ReadPic.aspx.vb</summary>
Imports System
Imports System.Drawing
Imports System.Drawing.Image
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Dim bmp As Bitmap = New Bitmap(Server.MapPath("") + "\picOWC.gif", True)
Response.ContentType = "image/gif"
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
Response.Flush()
bmp.Dispose()
End Sub
Imports System
Imports System.Drawing
Imports System.Drawing.Image
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Dim bmp As Bitmap = New Bitmap(Server.MapPath("") + "\picOWC.gif", True)
Response.ContentType = "image/gif"
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
Response.Flush()
bmp.Dispose()
End Sub