重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Public Class Form3
10年积累的做网站、网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计制作后付款的网站建设流程,更有策勒免费网站建设让你可以放心的选择与我们合作。
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
1、检查一下是不是序列的名称不对应,进行了修改,不是默认的"Series1";
3、修改正确或是没有错误时可全部重新生成一次看看。
希望对你有帮助,还有疑问请追问或是Hi
这个说起来有点小复杂,建议你找专门的文章学习。
比如:
TeeChart5
这个画图表很不错。。
百度一下一大堆下载的。