大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Public Class Form3
创新互联建站专注为客户提供全方位的互联网综合服务,包含不限于网站制作、成都做网站、徐闻网络推广、微信小程序开发、徐闻网络营销、徐闻企业策划、徐闻品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联建站为所有大学生创业者提供徐闻建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com
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
private void MyPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
public static boolean isNumeric(String str){
if(str.matches("//d*"){
return true;
}else{
return false;
}
}
在窗体上添加一个Chart1控件和一个Button1控件:
完整代码如下:(复制就可以用)
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Chart1.Series.RemoveAt(0) '清除原来的系列
Dim i As Integer
Dim j As Integer
For i = 0 To 11 '设置有12个系列
Chart1.Series.Add("系列" i + 1)
''添加数据点的个数
For j = 0 To 3 '设置有4个数据点
Chart1.Series(i).Points.Add()
Next
Next
'用生成的随机数(范围[2.0,9.9]),作为数据
Randomize()
For i = 0 To 11
For j = 0 To 3
Chart1.Series(i).Points(j).YValues = {Int((99 - 20 + 1) * Rnd() + 20) / 10} '将随机数据赋值给图表点的Y值
Next
Chart1.Series(i).ChartType = DataVisualization.Charting.SeriesChartType.Column '设置图表类型
Next
End Sub
End Class
VB.net与VB不同。
VB.net已经有专门绘图的类。
可以定义笔刷然后用Drawing类中的方法绘制。
Private Sub DrawEllipse()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawEllipse(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
Private Sub DrawRectangle()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawRectangle(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
1、检查一下是不是序列的名称不对应,进行了修改,不是默认的"Series1";
3、修改正确或是没有错误时可全部重新生成一次看看。
希望对你有帮助,还有疑问请追问或是Hi
vb2010以后的版本就自带Chart控件了,比如
Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Pie '饼图