大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
我自己写的控件,里面有示例程序,很简单的。不过饼图只设置了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)