我有一个Telerik RadHTMLChart,我通过模型渲染,该模型由SQLCommand填充。初始加载时,一切都很棒。网格渲染,它看起来像Telerik控件看起来一样好。但是,在第二页加载时,假设我单击第2页或第3页,网格将在顶部填充一个读取未定义的YAXIS。然后YAXIS数据呈现在底部。我调试了这个,在网上找不到任何关于此的内容。这是我的代码。假设我的SQL查询很棒并且效果很好,因为相信我,它确实很好。
For Each recordAboutUserRoles In usageData
If recordAboutUserRoles.usageCount <> 0 Then
Dim barz As New BarSeries
barz.Spacing = 0.4
barz.SeriesItems.Add(recordAboutUserRoles.usageCount, colorTheme.MainThemeColorLightened)
usageGraphByRole.PlotArea.Series.Add(barz)
i += 1
End If
Next
在此处将数据分配给模型
Private Function AssignData(ByVal data As SqlCommand) As List(Of RolesByUsageModel)
Dim result As SqlDataReader = data.ExecuteReader
Dim rolesByUsageModelList As New List(Of RolesByUsageModel)
While result.Read
Dim rolesByUsageModel As New RolesByUsageModel
rolesByUsageModel.usageCount = result.GetValue(0)
rolesByUsageModel.roleName = result.GetValue(1)
rolesByUsageModel.pageDefPageName = result.GetValue(2)
rolesByUsageModel.pathUrl = result.GetValue(3)
rolesByUsageModel.usageDetPageName = result.GetValue(4)
rolesByUsageModelList.Add(rolesByUsageModel)
End While
Return rolesByUsageModelList
End Function
这是我的WebForm标记。 AxnData:AxnChart是专有品牌。它只是Telerik RadHtmlChart的包装器。控制名称没有什么不同。
<AxnData:AxnChart ID="usageGraphByRole" runat="server">
<PlotArea>
<Series>
<telerik:BarSeries>
</telerik:BarSeries>
</Series>
</PlotArea>
<Legend>
<Appearance Visible="false"></Appearance>
</Legend>
<ChartTitle Text="Usage By Role"></ChartTitle>
</AxnData:AxnChart>
这是初始加载时图表的样子。
后续加载后的图表。
当我在DevTools中检查元素时,图表左侧的“d”实际上是Undefined。我试过给每个AXIS项目一个名字,但这似乎不起作用。
有人碰到过这个吗?
答案 0 :(得分:0)
简而言之,一切都错了。假设在Page_Load上调用usageGraph。然后调用DataBound事件。在DataBound事件中,在循环外部声明ChartSeries对象,并在循环内实例化一个新的Chart Series Item并添加到ChartSeries对象。
重要的是将所有数据分配保留在DataBound事件中。
Private Sub usageGraph()
usageGraphByRole.PlotArea.YAxis.LabelsAppearance.Visible = True
usageGraphByRole.DataSource = AssignData()
usageGraphByRole.DataBind()
End Sub
Private Sub usageGraphByRole_DataBound(sender As Object,e As EventArgs)处理usageGraphByRole.DataBound usageGraphByRole.PlotArea.Series.Clear()
Dim barz As New BarSeries()
barz.Name = "Usage By Roles"
'barz.LabelsAppearance.Visible = False
barz.TooltipsAppearance.DataFormatString = "{0} Usage Count, {1}"
For Each recordAboutUserRoles In AssignData()
If recordAboutUserRoles.usageCount <> 0 Then
Dim usageDataItem As New SeriesItem()
usageDataItem.YValue = recordAboutUserRoles.usageCount
barz.Items.Add(usageDataItem)
End If
Next
usageGraphByRole.PlotArea.Series.Add(barz)
End Sub