Dim Chart As WinForm.Chart '定义一个图表变量
Dim Series As WinForm.ChartSeries '定义一个图系变量
Dim t As Table = Tables("图表测试数据") '定义一个变量t引用数据表
Chart = e.Form.Controls("Chart2") ' 引用窗口中的图表
Chart.ChartType = ChartTypeEnum.Bar '图表类型改为Bar(条形)
Chart.SeriesList.Clear() '清除图表原来的图系
Chart.AxisY.Min = 0 '指定Y轴的最小值
Chart.AxisY.Max = 150 '指定Y轴的最大值
For Each c As Col In t.Cols
If c.Name <> "年份" And c.Name <> "月份" And c.Name <> "品牌" And c.Name <> "销售增长" Then
Series = Chart.SeriesList.Add() '增加一个图系
Series.Text = c.Name '设置图系的标题
Series.Length = t.Rows.Count '设置图系的长度
For r As Integer = 0 To t.Rows.Count - 1
Series.X(r) = r
Series.Y(r) = t.Rows(r)(c.Name)
Next
End If
Next
For r As Integer = 0 To t.Rows.Count - 1
Chart.AxisX.SetValueLabel(r, t.Rows(r)("月份") & "月份") '指定字符表示,设置X轴数值的字符表示
Next
Chart.AxisX.AnnoWithLabels = True '启用字符标示
Chart.VisualEffect = True '加上这一行,让你的图表更漂亮
Chart.LegendVisible = True '显示图列
Chart.LegendCompass = CompassEnum.South '图列显示在南方(底端)
'设置数据标示
For cc As Integer = 0 To Chart.SeriesList.count - 1
Chart.SeriesList(cc).DataLabelText = "{#YVAL}" '显示数据标点的值
Chart.SeriesList(cc).DataLabelCompass = LabelCompassEnum.North '设置数据标点值的位置
Next
'清除网格线
Chart.AxisX.GridMajorVisible = False
Chart.AxisY.GridMajorVisible = False
'设置图表区域样式2(去掉全部边框,并将全部背景设置为透明)
Chart.Style.Border.BorderStyle = C1Chart.BorderStyleEnum.None
Chart.ChartAreaStyle.Border.BorderStyle = C1Chart.BorderStyleEnum.None
Chart.Style.BackColor = Color.Transparent
Chart.ChartAreaStyle.BackColor = Color.Transparent
Chart.PlotAreaStyle.BackColor = Color.Transparent
'生成图表标题
Dim fnt As New Font("黑体", 18, FontStyle.Bold) '设置图表标题字体
Chart.HeaderText = "品牌各品类销售占比" '设置图表上标题
Chart.HeaderFont = fnt