使用Zedgraph图表库但我似乎无法根据特定条件为条形图着色。我跟随this tutorial上的示例。
在我的情况下,如果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的线条,以便学生可以快速看到学生已经或没有通过某个科目而不是通过标记
答案 0 :(得分:0)
我不知道它是否仍然相对,但你可以在ZedGraph中做多色条形图。 你可以在这里找到教程: http://zedgraph.dariowiz.com/indexb806.html?title=Multi-Colored_Bar_Demo
在你的情况下你可以使用FillType.GradientByColorValue我假设。 对于该行,您只需将LineObj添加到myPane.GraphObjList
即可