胖在一方

出得厅堂入得厨房的胖子

导航

Dundas Chart Demo

Posted on 2006-09-13 17:22  胖在一方  阅读(2094)  评论(1)    收藏  举报

从数据库绑定

 1    Dim Chart1 As New Chart
 2    Dim mySeries As New Series("Default")
 3    Dim myChartArea As New ChartArea
 4    Chart1.ChartAreas.Add(myChartArea)
 5 
 6    mySeries.Type = SeriesChartType.Column
 7 
 8    mySeries.Points.DataBindXY(ds.Tables("table").DefaultView, "name", ds.Tables("table").DefaultView, "sales")
 9    Chart1.Series.Add(mySeries)
10 
11    '显示Chart
12     Chart1.Page = Me
13     Chart1.RenderControl(New HtmlTextWriter(Page.Response.Output))
14     Chart1.Dispose()

DataBindXY方法如下
 1 Public Sub DataBindXY(ByVal xValue As System.Collections.IEnumerable, ByVal xField As StringByVal yValue As System.Collections.IEnumerable, ByVal yFields As String)
 2      成员属于: Dundas.Charting.WebControl.DataPointCollection
 3 
 4 摘要:
 5 Data bind X and Y values of the data points to the data source.  Data source can be the Array, Collection, Ole(SQL)DataReader, DataView, DataSet, DataTable or DataRow.  
 6 
 7 参数:
 8 xValue: Enumerable object with X values.
 9 xField: Name of the field for X values.
10 yValue: Enumerable objects with Y values.
11 yFields: Comma separated name(s) of the field(s) for Y value(s).
12 


以下是wincontrol的简单代码
 Dim myChart As Chart
        
Dim myChartArea As ChartArea
        
Dim mySeries As Series
       
        myChart 
= New Chart
        myChartArea 
= New ChartArea
        myChart.ChartAreas.Add(myChartArea)

        mySeries 
= New Series
        mySeries.Type 
= SeriesChartType.Column

        
Dim conn As New OracleConnection("data source=orcl;user id=scott;password=tiger;persist security info=false;")
        
Dim cmd As New OracleCommand("Select ename,sal From emp  ", conn)
        cmd.CommandType 
= CommandType.Text

        
Dim adp As New OracleDataAdapter(cmd)
        
Dim ds As New DataSet
        adp.Fill(ds, 
"d")
        mySeries.Points.DataBindXY(ds.Tables(
"d").DefaultView, "ename", ds.Tables("d").DefaultView, "sal")
        myChart.Series.Add(mySeries)

        myChartArea.AxisX.Interval 
= 1
        myChartArea.AxisY.Interval 
= 500
        myChart.Width 
= Me.Width
        myChart.Height 
= Me.Height - 300
        mySeries.ShowInLegend 
= False
        mySeries.ShowLabelAsValue 
= True
        
'myChart.BackHatchStyle = ChartHatchStyle.DashedHorizontal
        myChart.BorderColor = Color.DarkCyan
        
'myChartArea.AxisX.MajorTickMark.Style = TickMarkStyle.None
        'myChartArea.AxisY.MajorTickMark.Style = TickMarkStyle.None
        ' mySeries.Font = New Font("宋体", 10, FontStyle.Regular, GraphicsUnit.Display)
        ' myChartArea.AxisY.Arrows = ArrowsType.Triangle
        myChartArea.AxisX.MajorGrid.Enabled = False
        myChartArea.AxisX.Arrows 
= ArrowsType.Triangle
        myChartArea.AxisY.MajorGrid.Enabled 
= False
        myChartArea.AxisY.LabelStyle.Font 
= New Font("宋体"1)
        myChartArea.AxisY.Arrows 
= ArrowsType.Triangle
        myChart.BorderSkin.SkinStyle 
= Dundas.Charting.WinControl.BorderSkinStyle.Emboss

        
'myChart.Show()
        ' myChart.Visible = True

        
Me.Controls.Add(myChart)

添加警戒线(Cursor ,我自己的理解是警戒线)
 Dim cursorY As Dundas.Charting.WinControl.Cursor

        cursorY 
=
 myChartArea.CursorY
        cursorY.LineColor 
=
 Color.RoyalBlue
        cursorY.LineWidth 
= 2

        cursorY.LineStyle 
= ChartDashStyle.Solid
        cursorY.LineColor 
=
 Color.Red
        cursorY.SelectionColor 
=
 Color.Yellow
        cursorY.Position 
= 4500

控制字体

        myChartArea.AxisX.LabelsAutoFit 
= False
        myChartArea.AxisY.LabelsAutoFit 
= False
        myChartArea.AxisY.LabelStyle.Font 
= New Font("Arial"10)
        myChartArea.AxisX.LabelStyle.Font 
= New Font("Arial"10
)