[英]ASP Chart doesn't format correctly if XValueType=“Time” and Series contains DateTime which spans multiple days
我必须遵循代码,该代码显示一个表示一段时间内数据的图表。 如果所有数据都来自同一天,则图表显示正确,并且 X 轴刻度标记标签显示时间(以小时为单位)。 如果数据跨越两天,则图表会回到开头并与其他点重叠。 如果我设置 XValueType="DateTime",则系列绘制正确,但 X 轴刻度线标签变为日期,即使 IntervalType="Hours" 也是如此。 有什么方法可以让时间显示在 X 轴上,而无需将数据包装到图表的开头?
<asp:Chart ID="Chart1" BackColor="Black" Width="400px" Height="125px" DataSource='<%# DataBinder.Eval(Container.DataItem, "Metrics") %>'
runat="server">
<Series>
<asp:Series ChartType="Line" Name="Series1" YValueMembers="YValue" YValueType="Double"
XValueMember="Time" XValueType="Time">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1" BackColor="Black">
<AxisY Interval="50" LineColor="White" IsStartedFromZero="true" Maximum="100">
<MajorTickMark LineColor="White" Interval="10" />
<LabelStyle ForeColor="White" />
</AxisY>
<AxisX LineColor="White" IntervalType="Hours">
<LabelStyle ForeColor="White" />
<MajorTickMark LineColor="White" />
</AxisX>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
我通过设置 XValueType="DateTime" 并在 x 轴上格式化 label 以显示时间而不是日期来解决我的问题。 x 轴的代码现在如下:
<AxisX LineColor="White" IntervalType="Hours">
<LabelStyle ForeColor="White" Format="h:mm tt" />
<MajorTickMark LineColor="White" />
</AxisX>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.