Vb.net 使用Zedgraph库在条形图上自定义颜色

Vb.net 使用Zedgraph库在条形图上自定义颜色,vb.net,zedgraph,Vb.net,Zedgraph,我正在使用图表库,但我似乎无法根据特定条件为条形图着色。下面是我在上找到的示例 在我的例子中,如果该值不超过50(即student.pass_mark变量),我想将该条颜色设置为红色,如果该值高于50,我想将其设置为绿色。下面是我的代码。到目前为止,它只给我红色,即使我有100,80,110等值 Dim subject As String Dim grade As Decimal Dim colors As Color() = {} Dim subject_names As String() =

我正在使用图表库,但我似乎无法根据特定条件为条形图着色。下面是我在上找到的示例

在我的例子中,如果该值不超过50(即student.pass_mark变量),我想将该条颜色设置为红色,如果该值高于50,我想将其设置为绿色。下面是我的代码。到目前为止,它只给我红色,即使我有100,80,110等值

Dim subject As String
Dim grade As Decimal
Dim colors As Color() = {}
Dim subject_names As String() = {}
For i = 0 To student.no_of_subjects
    ReDim Preserve colors(i)
    ReDim Preserve subject_names(i)
    subject = student.subject_name
    grade = student.grade
    Dim x As Double = CDbl(i) + 1
    Dim y As Double = grade
    Dim z As Double = 0
    list.Add(x, y, z)
    If grade < student.pass_mark Then
        colors(i) = Color.Red
    Else
        colors(i) = Color.Green
    End If
    subject_names(i) = subject
Next

Dim myCurve As BarItem = myPane.AddBar("Student Subject", list, Color.Blue)
'Dim colors As Color() = {Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple}
myCurve.Bar.Fill = New Fill(colors)
myCurve.Bar.Fill.Type = FillType.Solid

myCurve.Bar.Fill.RangeMin = 0
myCurve.Bar.Fill.RangeMax = 4

myPane.Chart.Fill = New Fill(Color.White, Color.FromArgb(220, 220, 255), 45)
myPane.Fill = New Fill(Color.White, Color.FromArgb(255, 255, 225), 45)
' Tell ZedGraph to calculate the axis ranges
' Set the XAxis labels
myPane.XAxis.Scale.TextLabels = subject_names

' Set the XAxis to Text type
myPane.XAxis.Type = ZedGraph.AxisType.Text
ZedChart.IsShowPointValues = True
ZedChart.AxisChange()
ZedChart.Refresh()

另外,我想在整个图表上画一条线,显示及格分数,这样就可以很快地看到,与及格分数相比,学生是否通过了某个科目

我不知道它是否仍然是相对的,但你可以在ZedGraph中绘制多色条形图。 您可以在此处找到教程:

在您的情况下,我假设您可以使用FillType.GradientByColorValue。 对于该行,只需将LineObj添加到myPane.GraphbobJList即可