日期:2014-04-01  浏览次数:20556 次

OWC.aspx.vb:

Imports System
Imports OWC
Imports System.Web.UI

Public Class OWC
  Inherits System.Web.UI.Page
  Protected WithEvents ChartHolder As System.Web.UI.WebControls.PlaceHolder

#Region " Web 窗体设计器生成的代码 "

  '该调用是 Web 窗体设计器所必需的。
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

  End Sub

  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
    '不要使用代码编辑器修改它。
    InitializeComponent()
  End Sub

#End Region

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    '在此处放置初始化页的用户代码
    '创建ChartSpace对象来放置图表
    Dim objCSpace As ChartSpace = New ChartSpaceClass()
    '在ChartSpace对象中添加图表,Add方法返回chart对象
    Dim objChart As WCChart = objCSpace.Charts.Add(0)
    '指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到
    objChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered

    '指定图表是否需要图例
    objChart.HasLegend = True

    '给定标题
    objChart.HasTitle = True
    objChart.Title.Caption = "1-6说数据分布图"

    '给定x,y轴的图示说明
    objChart.Axes(0).HasTitle = True
    objChart.Axes(0).Title.Caption = "Y 轴 : 数量"
    objChart.Axes(1).HasTitle = True
    objChart.Axes(1).Title.Caption = "X 轴: 月份"

    '计算数据
    '*categories 和 values 可以用tab分割的字符串来表示*
    Dim strSeriesName As String = "图例 1"
    Dim strCategory As String = "1" + ControlChars.Tab + "2" + ControlChars.Tab _
    + "3" + ControlChars.Tab + "4" + ControlChars.Tab + "5" + ControlChars.Tab _
    + "6" + ControlChars.Tab
    Dim strValue As String = "9" + ControlChars.Tab + "8" + ControlChars.Tab _
    + "4" + ControlChars.Tab + "10" + ControlChars.Tab + "12" + ControlChars.Tab _
    + "6" + ControlChars.Tab

    '添加一个series
    objChart.SeriesCollection.Add(0)

    '给定series的名字
    objChart.SeriesCollection(0).SetData(ChartDimensionsEnum.chDimSeriesNames,_
     ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName)

    '给定分类
    objChart.SeriesCollection(0).SetData(ChartDimensionsEnum.chDimCategories,_
     ChartSpecialDataSourcesEnum.chDataLiteral, strCategory)

    '给定值
    objChart.SeriesCollection(0).SetData(ChartDimensionsEnum.chDimValues,_
     ChartSpecialDataSourcesEnum.chDataLiteral, strValue)
    '输出成GIF文件.
    Dim strAbsolutePath As String = (Server.MapPath(".")) + "\Images\test.gif"
    objCSpace.ExportPicture(strAbsolutePath, "GIF", 600, 350)

    '创建GIF文件的相对路径.
    Dim strRelativePath As String = "Images/test.gif"
    '把图片添加到placeholder.
    Dim strImageTag As String = "<IMG SRC='277_files/" + strrelativepath + "'/>"