Dim r As Row = Tables("表1").Current
If r Is Nothing Then
MessageBox.Show("没有记录!")
Return
Else
Dim Chart As WinForm.Chart
Dim dt As DataTable = DataTables("表1")
Dim t As Table = Tables("表1")
Dim n As Integer = t.Rows.Count
Dim dr1 As DataRow = dt.Find("[编号] = '" & r("编号") & "' And [任务] Like '%开始%'")
If dr1 Is Nothing Then
MessageBox.Show("没有开始日期!")
Return
Else
Chart= Forms("窗口1").Controls("Chart1")
Chart.ChartType = ChartTypeEnum.Gantt
Chart.Inverted = True '对调X轴和Y轴位置
Chart.AxisY.DateType= True 'Y轴为日期型
Chart.AxisY.AnnoFormatString = "yyyy-MM-dd" '设置Y轴的标示格式
Chart.AxisY.MinDate = dr1("日期") '设置Y轴的起始日期
End If
If n > 0 Then
Chart.AxisY.MaxDate = t.Rows(n-1)("日期") '设置Y轴的终止日期
Else
MessageBox.Show("没有记录!")
Forms("窗口1").Close
End If
Chart.AxisX.GridMajorVisible = False '隐藏X轴的网格线
With Chart.SeriesList
.AddGanttSeries("开始", dr1("日期"), dr1("日期").AddDays(3))
Dim dr20s As List(of DataRow)
dr20s = dt.Select("[编号] = '" & r("编号") & "' And [任务] Like '%任务三%'","日期")
For Each dr20 As DataRow In dr20s
.AddGanttSeries("任务三", dr20("日期"), dr20("日期").AddDays(3))
Next
Dim dr30s As List(of DataRow)
dr30s = dt.Select("[编号] = '" & r("编号") & "' And [任务] Like '%任务四%'","日期")
For Each dr30 As DataRow In dr30s
.AddGanttSeries("任务四", dr30("日期"), dr30("日期").AddDays(3))
Next
End With
End If
效果图如下:
此主题相关图片如下:2021-12-06_12-22-32.png
但我想要效果是这样的:
此主题相关图片如下:2021-12-06_12-22-42.png