Dim cd As String = e.Form.Controls("ComboBox_pcode").Value If cd > "" Then '---生成图表 Dim rqs As List(of String) = DataTables("表A").GetValues("采购日期","产品编码 = '" & cd & "'","采购日期") Dim Chart As WinForm.Chart '定义一个图表变量 Dim Series As WinForm.ChartSeries '定义一个图系变量 Chart = e.Form.Controls("Chart1") ' 引用窗口中的图表 Chart.DataSource = "表A" '设置绑定表 Chart.SeriesList.Clear() '清除图表原来的图系 Chart.Axisx.ClearValueLabel '清除设置的数值字符标示 ' Chart.AxisX.Max = rqs.Count + 1 '指定X轴的最大值 Series = Chart.SeriesList.Add() '增加一个图系 Series.Length = rqs.Count '设置图系的长度 For i As Integer = 0 To rqs.Count - 1 '指定每个数据点的位置 If i < rqs.Count Then Series.X(i) = i '指定水平坐标 Dim r As DataRow = DataTables("表A").Find("采购日期 = '" & rqs(i) & "'") '找出对应年月的行 If r IsNot Nothing '如果找到对应年月的行 Series.Y(i) = r("单价") '指定数量作为垂直坐标 Chart.AxisX.SetValueLabel(i,format(r("采购日期"), "yyyyMMdd")) '指定字符表示 End If End If Next Chart.AxisX.AnnoRotation = - 45 Chart.AxisX.AnnoWithLabels = True '启用字符标示 Series.LineColor = Color.LightSeaGreen Series.MarkShape = MarkShapeEnum.Dot Series.MarkColor = Color.Red End If
|