zed graph x axis labels
I am trying to loop through my datatable column sdescr and use the text in the columns as the labels of my x axis, but it isnt working i am getting this error
Value of type 'System.Collections.Generic.List(Of String)' cannot be converted to '1-dimensional array of String'.
For i As Integer = 0 To myCurve1.Points.Count - 1
开发者_如何学运维 Dim pt As PointPair = myCurve1.Points(i)
' Create a text label from the Y data value
Dim text As New TextObj(pt.Y.ToString("f0"), pt.X, pt.Y + 0.1, CoordType.AxisXYScale, AlignH.Left, AlignV.Center)
text.ZOrder = ZOrder.A_InFront
text.FontSpec.Angle = 90
myPane.GraphObjList.Add(text)
Dim labels As New List(Of String)
For Each row As DataRow In tablegraph.Rows
labels = row.Item("SDESCR")
Next row
myPane.XAxis.Scale.TextLabels = labels
myPane.XAxis.Type = AxisType.Text
Next
You need to remove the code to get the labels out of your For Next loop that is creating points.
Which means this
Dim labels As New List(Of String)
For Each row As DataRow In tablegraph.Rows
labels = row.Item("SDESCR")
Next row
myPane.XAxis.Scale.TextLabels = labels
myPane.XAxis.Type = AxisType.Text
Now, outside of the loop plotting points, you need to go through your DataTable
Please look at the error you're getting... The List of String can't be converted into a string array. Those objects aren't equivalent.
One option would be to do something like this (after your loop to plot points)
Dim labels(tablegraph.Rows.Count - 1) as String
For i As Integer = 0 To tablegraph.Rows.Count - 1
labels(i) = tablegraph.Row(i).Item("SDESCR")
Next
myPane.XAxis.Scale.TextLabels = labels
myPane.XAxis.Type = AxisType.Text
I don't have Zed here on this computer, so I haven't checked this in Visual Studio, but this should give you a very decent direction.
精彩评论