开发者

ASP Chart doesn't format correctly if XValueType="Time" and Series contains DateTime which spans multiple days

I have to following code which displays a chart that represents data over a period of time. If al开发者_开发知识库l the data is from the same day, the chart displays correctly, and the X axis tick mark labels display time in hours. If the data spans two days, the graph wraps to the beginning and overlaps other points. If I set the XValueType="DateTime" the series plots correctly but the X axis tick mark labels become dates, even thought the IntervalType="Hours". Is there any way I can get the hours to display on the X axis without having the data wrap to the beginning of the chart?

<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>


I solved my problem by setting the XValueType="DateTime" and formatting the label on the x axis to display the time, not the date. The code for the x axis is now the following:

<AxisX LineColor="White" IntervalType="Hours">
      <LabelStyle ForeColor="White" Format="h:mm tt" />
      <MajorTickMark LineColor="White" />
</AxisX>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜