我自己寫的控件,里面有示例程序,很簡單的。不過餅圖只設置了12種顏色。。。只能顯示12項
目前累計服務客戶1000多家,積累了豐富的產品開發及服務經驗。以網站設計水平和技術實力,樹立企業形象,為客戶提供成都網站制作、成都做網站、網站策劃、網頁設計、網絡營銷、VI設計、網站改版、漏洞修補等服務。創新互聯建站始終以務實、誠信為根本,不斷創新和提高建站品質,通過對領先技術的掌握、對創意設計的研究、對客戶形象的視覺傳遞、對應用系統的結合,為客戶提供更好的一站式互聯網解決方案,攜手廣大客戶,共同發展進步。
用宏功能啊,然后把宏代碼(vb6.0)轉化為Vb.net代碼,有一個關鍵問題,就是VBA中的枚舉類型在Vb.net中不適用,比如.End(xlUp)更改為.End(3)就能運行,另外vb.net中運行Excel對象不一定在點后會出現智能提示(即使你引用后也一樣)你只要確定有該方法或者屬性,直接寫就是了,生成或者調試都是可以通過的
Public?Class?Form3
Protected?Sub?iniChart()
Dim?dt?As?New?DataTable
'表增加月份、收入、支出三列
dt.Columns.Add("月份")
dt.Columns.Add("收入")
dt.Columns.Add("支出")
Dim?dr?As?DataRow
For?i?As?Integer?=?1?To?12
'新增行
dr?=?dt.NewRow()
'月份?1-12月
dr.Item(0)?=?i??"月"
Randomize()
'收入
dr.Item(1)?=?3000?+?Int(5000?*?Rnd(8))
Randomize()
'支出
dr.Item(2)?=?600?+?Int(2000?*?Rnd(7))
dt.Rows.Add(dr)
Next
dr?=?Nothing
With?Me.Chart1
.DataSource?=?dt????'dt作為chart1的數據源
.Series.Clear()
.Legends.Clear()
.ChartAreas.Clear()
.ChartAreas.Add("收入")
.ChartAreas.Add("支出")
.Legends.Add("收入")
.Legends.Add("支出")
.Series.Add("收入")
.Series.Add("支出")
.Series("支出").ChartArea?=?"支出"??????????????'指定Series所屬ChartArea
.Series("支出").Legend?=?"支出"?????????????????'指定Legend所屬Series
.Series("收入").LegendToolTip?=?"收入圖例"
.Series("收入").IsValueShownAsLabel?=?True????'標簽顯示數據值
.Legends("收入").DockedToChartArea?=?"收入"?????'指定Legend所屬ChartArea
.Legends("支出").DockedToChartArea?=?"支出"
.ChartAreas("支出").Area3DStyle.Enable3D?=?True??'啟用3D樣式
End?With
With?(Chart1.Series(0))
'指定x、y軸數據列
.YValueMembers?=?"收入"
.XValueMember?=?"月份"
'圖表類型
.ChartType?=?DataVisualization.Charting.SeriesChartType.Column
End?With
With?Chart1.Series(1)
.YValueMembers?=?"支出"
.XValueMember?=?"月份"
.ChartType?=?DataVisualization.Charting.SeriesChartType.Pie
End?With
Me.Chart1.DataBind()????'綁定數據源
With?Me.Chart1.Series("收入")
Dim?s1?As?Integer
For?i?As?Integer?=?0?To?.Points.Count?-?1
s1?=?s1?+?Val(.Points(i).GetValueByName("y"))
.Points(i).ToolTip?=?.Points(i).AxisLabel??.Points(i).GetValueByName("y")
Next
'圖例顯示總收入
Me.Chart1.Legends("收入").Title?=?"總收入"
.LegendText?=?s1.ToString
End?With
With?Me.Chart1.Series("支出")
.IsValueShownAsLabel?=?True
For?i?As?Integer?=?0?To?.Points.Count?-?1
.Points(i).ToolTip?=?.Points(i).AxisLabel??.Points(i).GetValueByName("y")
.Points(i).LegendText?=?.Points(i).AxisLabel
.Points(i).Label?=?"#PERCENT"???????????????'餅狀圖顯示百分比
.SmartLabelStyle.AllowOutsidePlotArea?=?True
Next
End?With
Me.Chart1.AlignDataPointsByAxisLabel("支出")
With?Me.Chart1.Legends("支出")
.LegendStyle?=?DataVisualization.Charting.LegendStyle.Column
.Title?=?"支出"
End?With
End?Sub
Private?Sub?Form3_Load(ByVal?sender?As?Object,?ByVal?e?As?System.EventArgs)?Handles?Me.Load
Call?iniChart()
Call?iniCombChart()
End?Sub
Private?Sub?iniCombChart()
Dim?tps?As?Array
'枚舉所有SeriesChartType類型
tps?=?System.Enum.GetValues(GetType(Windows.Forms.DataVisualization.Charting.SeriesChartType))
For?Each?i?As?Windows.Forms.DataVisualization.Charting.SeriesChartType?In?tps
Me.ComboBox1.Items.Add(Val(i))
Next
End?Sub
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
Call?iniChart()
End?Sub
Private?Sub?ComboBox1_SelectedIndexChanged(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?ComboBox1.SelectedIndexChanged
With?Chart1.Series(0)
'改變圖表樣式
Dim?tps?As?Array
tps?=?System.Enum.GetValues(GetType(System.Windows.Forms.DataVisualization.Charting.SeriesChartType))
For?Each?i?As?Windows.Forms.DataVisualization.Charting.SeriesChartType?In?tps
If?Val(i)?=?Me.ComboBox1.Text?Then
.ChartType?=?i
Exit?For
End?If
Next
End?With
End?Sub
End?Class
先在“部件”里選上“Microsoft Chart Control 6.0”,并添加一個MSChart1。
Private Sub Form_Load()
With MSChart1
.chartType = VtChChartType2dPie '表示餅圖
.ColumnCount = 3 '這里是每個餅圖的數據個數
.ColumnLabel = "你的數據名稱"
.RandomFill = True '暫且用隨機數填圖,數據請自己輸入
.RowCount = 2 '你說的“畫兩部分的餅狀圖就成”
.RowLabel = "你的數據標簽"
.TitleText = "你的圖表名稱"
End With
End Sub
Dim MyGraphics As Graphics = Me.PictureBox1.CreateGraphics
Dim MyBrush As New SolidBrush(Color.Red)
Dim MyProportion As Single
Dim MyRect As New Rectangle
Dim MyPoint As New PointF
Dim R As Single
Const PI = 3.1415926
MyGraphics.Clear(Color.White)
Dim MyStartAngel As Double
Dim MySweepAngel As Double
R = Math.Min(Me.PictureBox1.Width, Me.PictureBox1.Height) / 2 - 15
MyPoint.X = Me.PictureBox1.Width / 2
MyPoint.Y = Me.PictureBox1.Height / 2
MyRect.X = MyPoint.X - R
MyRect.Y = MyPoint.Y - R
MyRect.Width = R * 2
MyRect.Height = R * 2
MyStartAngel = 0
MyProportion = Val(TextBox7.Text)
MySweepAngel = MyProportion * 360 / PI
MyBrush.Color = Color.Red
MyGraphics.FillPie(MyBrush, MyRect, MyStartAngel, MySweepAngel)
' MyStartAngel = MyStartAngel + MySweepAngel
MyProportion = 0.75
MySweepAngel = 360 * MyProportion
MyBrush.Color = Color.Blue
MyGraphics.FillPie(MyBrush, MyRect, MyStartAngel, MySweepAngel)
標題名稱:vb.net繪制餅狀圖,繪制餅圖的函數
文章出自:http://m.newbst.com/article36/phhspg.html
成都網站建設公司_創新互聯,為您提供服務器托管、網站導航、軟件開發、定制開發、企業建站、全網營銷推廣
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯