DevExpress 图表控件 showing/plotting 整数值作为小数,在数学上没有意义
DevExpress Chart Control showing/plotting integer values as decimals that doesn't make sense mathematically
所以问题是为什么它以没有意义的小数显示数据,这是屏幕截图
控制台输出如下:
fVal: 1| fTime: 06:00:00
fVal: 1| fTime: 08:00:00
fVal: 1| fTime: 09:00:00
fVal: 1| fTime: 10:00:00
fVal: 1| fTime: 12:00:00
fVal: 2| fTime: 13:00:00
fVal: 2| fTime: 18:00:00
如您所见,这些值不是小数。但是当绘制在图表上时,它显示为小数。
我尝试过的事情:
- 使用 devexpress 的最佳实践示例
- 同时使用 .add、.addrange 和 .addpoint 方法,但它们都是
显示相同的错误。
- 正在插入一个新的图表控件。
这是我的代码:
Private Sub initSeriesData_Hourly() 'Count how many documents in a day is processed(globally)
Dim dataList As List(Of TimeSpan) = datasetHourly()
Dim dtList As New List(Of DateTime)
If Not dataList Is Nothing Then
For x As Integer = 0 To dataList.Count - 1
Dim dt As DateTime = New DateTime() + dataList.Item(x)
dtList.Add(dt)
Next
End If
Dim dataList_Count = countDateTime(dtList)
chart_ProcessedDocuments.RefreshData()
Dim pDoc_Series_1 As Series = chart_ProcessedDocuments.Series("Processed Documents(Hourly)")
If Not dataList_Count Is Nothing Then
Dim val As New List(Of Integer)
Dim time_ As New List(Of TimeSpan)
For hourData As Integer = 0 To dataList_Count.Count - 1
Dim timeSpanSplit = dataList_Count.Item(hourData).Split("|")
time_.Add(TimeSpan.Parse(timeSpanSplit(0)))
val.Add(timeSpanSplit(1))
Console.WriteLine(timeSpanSplit(0) + "|" + timeSpanSplit(1))
Next
'Dim pointscount = 24
'Dim pointsList As New List(Of SeriesPoint)
Dim fTime_List As New List(Of TimeSpan)
Dim fVal_List As New List(Of Integer)
For i As Integer = 0 To 23
Dim intTime As TimeSpan = TimeSpan.FromHours(i) 'Converts integer to timespan format
Dim fVal As Integer
Dim fTime As TimeSpan
If time_.Count > 0 Then
For j As Integer = 0 To time_.Count - 1
If intTime = time_(j) Then
fVal = val(j)
fTime = intTime
Console.WriteLine("fVal: " + fVal.ToString + "| fTime: " + fTime.ToString)
Else
fVal = 0
fTime = intTime
End If
fTime_List.Add(fTime)
fVal_List.Add(fVal)
Next
End If
Next
If fVal_List.Count > 0 Then
For length = 0 To fVal_List.Count - 1
Dim pointPlot As New SeriesPoint(fTime_List.Item(length), fVal_List.Item(length))
pDoc_Series_1.Points.Add(pointPlot)
Next
End If
Else
End If
End Sub
抱歉,代码看起来不太好,因为我已经尝试解决这个问题 2 天了。
发现循环超过 24,并且每次迭代都以某种方式超过 reduces/divides 绘制值。
将循环更改为:
For index_0 As Integer = 0 To cTime_List.Count - 1
For index_1 As Integer = 0 To time_.Count - 1
If cTime_List.Item(index_0) = time_.Item(index_1) Then
Dim oldVal = cVal_List.Item(index_0)
cVal_List.Item(index_0) = val.Item(index_1)
Console.WriteLine(cTime_List.Item(index_0).ToString + "=" + time_.Item(index_1).ToString)
Console.WriteLine(oldVal.ToString + "<->" + val.Item(index_1).ToString)
End If
Next
'Console.WriteLine(index_0)
Dim pointPlot_1 As New SeriesPoint(cTime_List.Item(index_0), (cVal_List.Item(index_0)))
pDoc_Series_1.Points.Add(pointPlot_1)
Next
所以问题是为什么它以没有意义的小数显示数据,这是屏幕截图
控制台输出如下:
fVal: 1| fTime: 06:00:00
fVal: 1| fTime: 08:00:00
fVal: 1| fTime: 09:00:00
fVal: 1| fTime: 10:00:00
fVal: 1| fTime: 12:00:00
fVal: 2| fTime: 13:00:00
fVal: 2| fTime: 18:00:00
如您所见,这些值不是小数。但是当绘制在图表上时,它显示为小数。 我尝试过的事情:
- 使用 devexpress 的最佳实践示例
- 同时使用 .add、.addrange 和 .addpoint 方法,但它们都是 显示相同的错误。
- 正在插入一个新的图表控件。
这是我的代码:
Private Sub initSeriesData_Hourly() 'Count how many documents in a day is processed(globally)
Dim dataList As List(Of TimeSpan) = datasetHourly()
Dim dtList As New List(Of DateTime)
If Not dataList Is Nothing Then
For x As Integer = 0 To dataList.Count - 1
Dim dt As DateTime = New DateTime() + dataList.Item(x)
dtList.Add(dt)
Next
End If
Dim dataList_Count = countDateTime(dtList)
chart_ProcessedDocuments.RefreshData()
Dim pDoc_Series_1 As Series = chart_ProcessedDocuments.Series("Processed Documents(Hourly)")
If Not dataList_Count Is Nothing Then
Dim val As New List(Of Integer)
Dim time_ As New List(Of TimeSpan)
For hourData As Integer = 0 To dataList_Count.Count - 1
Dim timeSpanSplit = dataList_Count.Item(hourData).Split("|")
time_.Add(TimeSpan.Parse(timeSpanSplit(0)))
val.Add(timeSpanSplit(1))
Console.WriteLine(timeSpanSplit(0) + "|" + timeSpanSplit(1))
Next
'Dim pointscount = 24
'Dim pointsList As New List(Of SeriesPoint)
Dim fTime_List As New List(Of TimeSpan)
Dim fVal_List As New List(Of Integer)
For i As Integer = 0 To 23
Dim intTime As TimeSpan = TimeSpan.FromHours(i) 'Converts integer to timespan format
Dim fVal As Integer
Dim fTime As TimeSpan
If time_.Count > 0 Then
For j As Integer = 0 To time_.Count - 1
If intTime = time_(j) Then
fVal = val(j)
fTime = intTime
Console.WriteLine("fVal: " + fVal.ToString + "| fTime: " + fTime.ToString)
Else
fVal = 0
fTime = intTime
End If
fTime_List.Add(fTime)
fVal_List.Add(fVal)
Next
End If
Next
If fVal_List.Count > 0 Then
For length = 0 To fVal_List.Count - 1
Dim pointPlot As New SeriesPoint(fTime_List.Item(length), fVal_List.Item(length))
pDoc_Series_1.Points.Add(pointPlot)
Next
End If
Else
End If
End Sub
抱歉,代码看起来不太好,因为我已经尝试解决这个问题 2 天了。
发现循环超过 24,并且每次迭代都以某种方式超过 reduces/divides 绘制值。
将循环更改为:
For index_0 As Integer = 0 To cTime_List.Count - 1
For index_1 As Integer = 0 To time_.Count - 1
If cTime_List.Item(index_0) = time_.Item(index_1) Then
Dim oldVal = cVal_List.Item(index_0)
cVal_List.Item(index_0) = val.Item(index_1)
Console.WriteLine(cTime_List.Item(index_0).ToString + "=" + time_.Item(index_1).ToString)
Console.WriteLine(oldVal.ToString + "<->" + val.Item(index_1).ToString)
End If
Next
'Console.WriteLine(index_0)
Dim pointPlot_1 As New SeriesPoint(cTime_List.Item(index_0), (cVal_List.Item(index_0)))
pDoc_Series_1.Points.Add(pointPlot_1)
Next