2014-02-17 108 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線,使其迅速可見的是一個學生'已經或沒有通過某個科目的比較

回答