2014-02-17 79 views
0

正在使用Zedgraph图表库,但我似乎无法根据特定条件为条形图着色。以下是this tutorial上的示例。使用Zedgraph库的条形图上的自定义颜色

在我的情况下,如果value不超过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() 

另外,我想提请在整个图表,显示了pass_mark线,使其迅速可见的是一个学生'已经或没有通过某个科目的比较

回答